I was calculated using the Simpson 1/3 rule numerical method, why my running results doesn't appear in the command window?

1 回表示 (過去 30 日間)
Beatrice
Beatrice 2023 年 11 月 27 日
回答済み: Torsten 2023 年 11 月 28 日
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

回答 (2 件)

ScottB
ScottB 2023 年 11 月 27 日
A semi-colon at the end of a line suppresses display of the result.

Torsten
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
i = 9.3333
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
ai = 9.8333
et=(i-ai)/i*100;

カテゴリ

Help Center および File ExchangeProgramming についてさらに検索

製品


リリース

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by