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 CenterFile Exchange에서 Programming에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by