How can i solve the Too many output arguments error problem ?

3 visualizaciones (últimos 30 días)
Hazel Can
Hazel Can el 2 de En. de 2023
Comentada: Star Strider el 2 de En. de 2023
clc
clear
syms x
f=input('\n Enter the function f(x): '); %inline('((x^2)*log(x))')
f=@ (x) (x^2)*log(x)
a=input('Enter lower limit a: '); % for our example a=1
b=input('Enter upper limit b: '); % for our example b=5
n=input('Enter the number of sub-intervals n: '); % for our example n=8,16,32
h=(b-a)/n;
Df=diff((x.^2)*log(x),x,4);
if rem(n,2)==1
fprintf('\n Enter valid n!!!');
n=input('\n Enter n as even number ');
end
so=0;
se=0;
for k=1:1:n-1
x(k)=a+k*h;
y(k)=f(x(k));
if rem(k,2)==1
so=so+y(k);%sum of odd terms
else
se=se+y(k); %sum of even terms
end
end
% Formula: (h/3)*[(y0+yn)+4*(y1+y3+y5+..odd term)+2*(y2+y4+y6+...even terms)]
answer=h/3*(f(a)+f(b)+4*so+2*se);
Error=-(((b-a)/180)*(h^4)*(Df))
fprintf('\n The value of integration is %f',answer);
fprintf('\n The value of error is %f',error);
and after the run, error is :
Error using error
Too many output arguments.
Error in compos (line 30)
fprintf('\n The value of error is %f',error);

Respuestas (1)

Star Strider
Star Strider el 2 de En. de 2023
You are overshadowing the error function (although there are also two other error functions in the Statistics and Machine Learning Toolbox that do have outputs).
fprintf('\n The value of error is %f',error);
Error using error
Too many output arguments.
In any event, it should probably be:
Error=-(((b-a)/180)*(h^4)*(Df))
fprintf('\n The value of error is %f',Error);
instead.
.
  2 comentarios
Torsten
Torsten el 2 de En. de 2023
... and since "Error" is symbolic, it cannot be printed the way you do.

Iniciar sesión para comentar.

Productos


Versión

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by