If function, Index exceeds matrix dimensions.
Mostrar comentarios más antiguos
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 comentarios
Star Strider
el 5 de Feb. de 2019
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
el 6 de Feb. de 2019
Respuesta aceptada
Más respuestas (1)
Walter Roberson
el 6 de Feb. de 2019
0 votos
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 .
Categorías
Más información sobre Common Operations en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!