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

조회 수: 1 (최근 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

답변 (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 CenterFile Exchange에서 Programming에 대해 자세히 알아보기

제품


릴리스

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by