Input Function of (x,y) For Loop Error

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);

 Respuesta aceptada

Walter Roberson
Walter Roberson el 3 de Abr. de 2016
dy_string = input ('dy/dx = ','s');
dy = str2fun( ['@(x,y) ', dy_string] );

2 comentarios

thank you @Walter this help in convert the string to function
still there that error
Not enough input arguments.
when enter the for loop that when make the loop like that
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 was
Matrix dimensions must agree.
Error in Final>@(x,y)x-y
Error in Final (line 500)
dy(o+1) = feval(dy,x,y);
dy(x,y)
with no feval.
However, do not assign the output to dy(o+1) . dy is a function handle . If you need a record of the output of the function, use a different variable.
y(o+1) = y(o) + delx * dy(x(o), y(o));
dy_val(o+1) = dy(x(o), y(o+1));
However you need to think about whether the second dy calculation should use x(o) or x(o+1)

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Function Creation en Centro de ayuda y File Exchange.

Productos

Preguntada:

el 3 de Abr. de 2016

Comentada:

el 5 de Abr. de 2016

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by