matlab 用if编简单的 分段函数
function[Y]=thli(X)%UNTITLEDSummaryofthisfunctiongoeshere%Detailedexplanationgoeshere...
function [Y]= thli(X)
%UNTITLED Summary of this function goes here
% Detailed explanation goes here
%x = 0:0.1:1
if X<=0.1
Y=1000*X;
end
if X>0.1 && X<=0.2
Y=2*50000*(X-0.1)+100;
end
if X>0.2 && X<=0.25
Y=50*50000*(X-0.2)+2*50000*0.1+100;
end
if X>0.25
Y=100;
end
end
总是出错:??? Input argument "X" is undefined.
Error in ==> thli at 5
if X<=0.1
求高手帮忙,谢谢啦;
谢谢你的帮忙,不过结果运行怎么基本是0啊。
ans =
Columns 1 through 16
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Columns 17 through 32
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Columns 33 through 48
0 0 0 0 0 展开
%UNTITLED Summary of this function goes here
% Detailed explanation goes here
%x = 0:0.1:1
if X<=0.1
Y=1000*X;
end
if X>0.1 && X<=0.2
Y=2*50000*(X-0.1)+100;
end
if X>0.2 && X<=0.25
Y=50*50000*(X-0.2)+2*50000*0.1+100;
end
if X>0.25
Y=100;
end
end
总是出错:??? Input argument "X" is undefined.
Error in ==> thli at 5
if X<=0.1
求高手帮忙,谢谢啦;
谢谢你的帮忙,不过结果运行怎么基本是0啊。
ans =
Columns 1 through 16
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Columns 17 through 32
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Columns 33 through 48
0 0 0 0 0 展开
3个回答
展开全部
!!!应该是这样的结果吧!!!!
程序如下:
function y= thli(x)
%UNTITLED Summary of this function goes here
% Detailed explanation goes here
%x = 0:0.1:1
if x<=0.1
y=1000*x;
elseif x>0.1
y=2*50000*(x-0.1)+100;
elseif x<=0.2
y=2*50000*(x-0.1)+100;
elseif x>0.2
y=50*50000*(x-0.2)+2*50000*0.1+100;
elseif x<=0.25
y=50*50000*(x-0.2)+2*50000*0.1+100;
elseif x>0.25
y=100;
end
程序如下:
function y= thli(x)
%UNTITLED Summary of this function goes here
% Detailed explanation goes here
%x = 0:0.1:1
if x<=0.1
y=1000*x;
elseif x>0.1
y=2*50000*(x-0.1)+100;
elseif x<=0.2
y=2*50000*(x-0.1)+100;
elseif x>0.2
y=50*50000*(x-0.2)+2*50000*0.1+100;
elseif x<=0.25
y=50*50000*(x-0.2)+2*50000*0.1+100;
elseif x>0.25
y=100;
end
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
function [y,x]= thli(x)
%UNTITLED Summary of this function goes here
% Detailed explanation goes here
if nargin==0
x = 0:0.01:1;
end
for i=1:length(x)
X=x(i);
if X<=0.1
Y=1000*X;
end
if X>0.1 && X<=0.2
Y=2*50000*(X-0.1)+100;
end
if X>0.2 && X<=0.25
Y=50*50000*(X-0.2)+2*50000*0.1+100;
end
if X>0.25
Y=100;
end
end
y(i)=Y;
end
%%%%%%%%%%%
调用一下啊!
我是这样用的。
[y,x]= thli();plot(x,y)
你看看结果吧
%UNTITLED Summary of this function goes here
% Detailed explanation goes here
if nargin==0
x = 0:0.01:1;
end
for i=1:length(x)
X=x(i);
if X<=0.1
Y=1000*X;
end
if X>0.1 && X<=0.2
Y=2*50000*(X-0.1)+100;
end
if X>0.2 && X<=0.25
Y=50*50000*(X-0.2)+2*50000*0.1+100;
end
if X>0.25
Y=100;
end
end
y(i)=Y;
end
%%%%%%%%%%%
调用一下啊!
我是这样用的。
[y,x]= thli();plot(x,y)
你看看结果吧
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询