I was calculated using the Simpson 1/3 rule numerical method, why my running results doesn't appear in the command window?
2 次查看(过去 30 天)
显示 更早的评论
clear all;
clc;
%input data
a=0;
b=2;
c=1; %centre
f_2=(-1/4*(2)^4)-(1/3*(2)^3)+(5/2*(2)^2)+3*2;
f_0=(-1/4*(0)^4)-(1/3*(0)^3)+(5/2*(0)^2)+3*0;
i=(f_2)-(f_0); %exact
x0=0;
xa=(-x0^3-x0^2+5*x0+3);
x1=0.5;
xb=(-x1^3-x1^2+5*x1+3);
x2=1;
xc=(-x2^3-x2^2+5*x2+3);
ai=((b-a)/6)*(xa+4*(xc)+xb); %main equation
et=(i-ai)/i*100;
i created my own script. the result appear on the workshop, but why it dosen't appear on command window?
please tell me where did i go wrong and how to fix it
0 个评论
回答(2 个)
Torsten
2023-11-28
Use
ai=((b-a)/6)*(xa+4*(xb)+xc) %main equation
instead of
ai=((b-a)/6)*(xa+4*(xc)+xb) %main equation
clear all;
clc;
%input data
a=0;
b=2;
c=1; %centre
f_2=(-1/4*(2)^4)-(1/3*(2)^3)+(5/2*(2)^2)+3*2;
f_0=(-1/4*(0)^4)-(1/3*(0)^3)+(5/2*(0)^2)+3*0;
i=(f_2)-(f_0) %exact
x0=0;
xa=(-x0^3-x0^2+5*x0+3);
x1=0.5;
xb=(-x1^3-x1^2+5*x1+3);
x2=1;
xc=(-x2^3-x2^2+5*x2+3);
ai=((b-a)/6)*(xa+4*(xb)+xc) %main equation
et=(i-ai)/i*100;
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!