How can i solve the Too many output arguments error problem ?
3 ビュー (過去 30 日間)
古いコメントを表示
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);
0 件のコメント
回答 (1 件)
Star Strider
2023 年 1 月 2 日
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);
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 件のコメント
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!