Error using feval Argument must contain a string or function_handle.
6 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(1 个)
Jan
2018-6-3
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 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!