MATLAB: Input Function of (x,y) For Loop Error

errorerrorsfevalinline()inputMATLABode

i'm trying to input function of x,y
dy = input ('dy/dx = ','s');
dy = @(x,y) dy;
and also try
dy = input ('dy/dx = ','s');
dy = inline(dy);
then make a for loop to calculate y(2) based on the value of y(1) and dy(1) ===> which a function x,y
for o = 1 : 1 : n
y(o+1) = y(o) + delx * dy(x(o),y(o));
dy(o+1) = feval(dy,x,y);
end
here I want to use the just calculated y(2) to calculate the value of dy(2) and when run that code give me that error
In an assignment A(:) = B, the number of elements in A and B must be the same.
Error in Final (line 500)
y(o+1) = y(o) + delx * dy(x(o),y(o));
===================================================
update:
thank you (@Walter Roberson)
this help in convert the string to function
still there that error
Not enough input arguments.
when enter the for loop
for o = 1 : 1 : n
y(o+1) = y(o) + delx * dy(x(o),y(o));
dy(x(o+1),y(o+1)) = feval(dy(o),x(o),y(o));
end
and when made it
for o = 1 : 1 : n
y(o+1) = y(o) + delx * dy(x(o),y(o));
dy(o+1) = feval(dy,x,y);
end
the error is
Matrix dimensions must agree.
Error in Final>@(x,y)x-y
Error in Final (line 500)
dy(o+1) = feval(dy,x,y);

Best Answer

dy_string = input ('dy/dx = ','s');
dy = str2fun( ['@(x,y) ', dy_string] );
Related Question