Error using feval Argument must contain a string or function_handle.

6 ビュー (過去 30 日間)
Paola Vázquez
Paola Vázquez 2018 年 6 月 3 日
回答済み: Jan 2018 年 6 月 3 日
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)

回答 (1 件)

Jan
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.

カテゴリ

Help Center および File ExchangeProgramming についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by