0

I'm learning about programming in MATLAB and I'm getting some annoying problems with it

The error i get is the following:

"Error using feval
Argument must contain a string or function_handle.

Error in Trapecio (line 26)
 Area=(h/2)*(feval(a)+(2*s)+feval(b));"

I am putting sin(x) at the start of the program in this line:

f = input('introduce la funcion: '); 

I am not sure what to do here. Any help would be appreciated!

clear all; 
clc; 

fprintf('Calculo de la integral por el metodo trapecial\n\n'); 

f=input('introduce la funcion: '); 

a=input('limite inferior: '); 

b=input('limite superior: '); 

n=input('numero de segmentos a dividir:'); 

x=a;

s=0;

h=(b-a)/n;

if n==1
    Area=(h/2)*(feval(a)+(2*s)+feval(b));
else
i=1;
for i=1:(n-1);
        x=x+h;
        s=s+subs(f,'x',x);
    %i=i+1;
end

Area=(h/2)*(feval(a)+(2*s)+feval(b));

disp('Area= ');

disp(Area);

end

1 Answer 1

1

Feval requires a function handle as the first argument. You are passing it a string. Use eval instead and pass it a string expression. Check the documentation for eval.

Sign up to request clarification or add additional context in comments.

1 Comment

+1 on reading MATLAB documentation. Welcome to StackOverflow Jaxor24!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.