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

1 visualizzazione (ultimi 30 giorni)
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

Risposte (2)

ScottB
ScottB il 27 Nov 2023
A semi-colon at the end of a line suppresses display of the result.

Torsten
Torsten il 28 Nov 2023
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;

Categorie

Scopri di più su Programming in Help Center e File Exchange

Prodotti


Release

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by