Error using feval Argument must contain a string or function_handle.
6 views (last 30 days)
Show older comments
a=input('ingresa el inicio del dominio de t:');
b=input('ingresa el fin del dominio de t:');
n=input('ingresa el # de particiones del dominio t:');
h=(b-a)/n;
t=a:h:b; %dominio
f=input('ingresa la función completa a resolver:');
y0=input('ingresa la condición inicial para y:');
%variables de Euler
y=zeros(1,n+1);%reservamos memoria
y(1)=y0;
for i=1:length(t)-1
y(i+1)=y(i)+h*feval(f,t(i),y(i));
end
figure (1)
xlabel ('X')
ylabel('Y')
plot(t,y)
0 Comments
Answers (1)
Jan
on 3 Jun 2018
After
f = input('ingresa la función completa a resolver:')
the variable f contains numerical values. Either use
f = input('ingresa la función completa a resolver:', 's')
or much better: Define the function by code, not by an input command. If the user provides the data by input, it is hard and tedious to repeat the evaluation. In consequence this impedes debugging. Prefer to write a function and define the data as input arguments.
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!