MATLAB question Please write the mfile with using Trapezoida

MATLAB question.

Please write the m-file with using Trapezoidal rule and Simpsons rule.

The question is below.

Thanks!

Use MAT LAB to integrate the following data sets: Display the result to the Command Window

Solution

Ans)

You can do the tarpezoidal integration using matlab inbuilt command ,but for simpson\'s rule you need matlab function given below

--------------------

simpson\'s rule code

-----------------

function z = simps(x,y,dim)

------------------------------------

Matlab code for problem given

------------------------------


%16.2a problem
x=[0 0.25 0.5 0.75 1];
y=[0 0.0632 0.2619 0.6350 1.3105];
integration1=trapz(x,y);
fprintf(\'Answer to problem 16.2a is =%2.4f\ \',integration1);

%16.2b problem
x=[1 1.3333 1.6667 2 2.3333 2.6667 3];
y=[1.3105 4.0158 -10.3510 -1.9869 -0.7569 -0.2351 -0.0201];
integration2=simps(x,y);
fprintf(\'Answer to problem 16.2b is =%2.4f\ \',integration2);

%16.2b problem
x=[1 1.2857 1.5714 1.8571 2.1429 2.4286 2.7143 3];
y=[1.3105 3.2745 -1581.7 -3.258 -1.3058 -0.56568 -0.18871 -0.020116];
integration3=simps(x,y);
fprintf(\'Answer to problem 16.2c is =%8.4f\ \',integration3);

-----------------------------------------

Result in command window is

------------------------

>> ic16_2
Answer to problem 16.2a is =0.4038
Answer to problem 16.2b is =-1.5280
Answer to problem 16.2c is =-301.6110
>>

--------------------------

MATLAB question. Please write the m-file with using Trapezoidal rule and Simpsons rule. The question is below. Thanks! Use MAT LAB to integrate the following da

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site