If function, Index exceeds matrix dimensions.
显示 更早的评论
Hi All, my code is:
syms x y m n;
funt=@(x,m,n,y) (100-10-x+y).^(-0.5)-(2.*n+4.*m.*y);
if funt(x,m,n,0)<=0
funfun(x,m,n)=0;
elseif funt(x,m,n,50)>=0
funfun(x,m,n)=50;
else funfun(x,m,n)=fzero(@(y) (100-10-x+y).^(-0.5)-(2.*n+4.*m.*y),[0,50]);
end
feval(funfun,10,0.002,0.4)
The error is:
Conversion to logical from sym is not possible.
I would like to construct a function of x and z. z can be regarded as an input and the range of x is [0,50]. Then I test this function at the value of 10 and z=[0.002,0.4]. This is my first time to use if function in matlab. So it might be some errors in my code. Thank you so much in advance. Any help is appreciated!
2 个评论
Star Strider
2019-2-5
The error is:
Index exceeds matrix dimensions.
This is most likely because ‘funfun’ does not exist until you define it here (as a matrix, not a function).
What what is ‘funfun’, and do you want to do with ‘funfun’?
James_111
2019-2-6
采纳的回答
更多回答(1 个)
Walter Roberson
2019-2-6
0 个投票
You need to switch to using piecewise()
Note that if you matlabFunction an expression involving piecewise then you must specify the 'File' option and what you get out will not be vectorized with respect to that variable .
类别
在 帮助中心 和 File Exchange 中查找有关 Common Operations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!