(In Matlab) Write a script file (i.e. a non-function) “simpson.m” that computes
ID: 3676899 • Letter: #
Question
(In Matlab) Write a script file (i.e. a non-function) “simpson.m” that computes the integral
of this “f(x)=24sin(10x)+2x^2+4” using the “Multiple-Application” Simpson’s 1/3 Rule with n = 5, 50, and 500:
Your script file should include:
a) Request from user to input the following values: n, a ( = 0), and b ( = 5).
b) Clear (and nicely formatted) output display of the computed integral “I” and comparison with the actual exact integral value.
c) Clear statement indicating which method was used to compute the integral “I.”
n-1 n-2 Xj) + 1=(b-a) 3)0Explanation / Answer
NOTE: To find integration in MATLAB first download Symbolic Math Toolbox
clc
clear all
n = input ('Enter n');
a = input ('Enter a');
b = input ('Enter b');
disp('Integral using int function')
syms x
f = '24*sin(10*x)+2*(x^2)+4'
int(sym(f),x= a..b)
prettyint(sym(f))
disp('Integral using Simpson's 1/3 rule')
h = (b-a)/n
p=0;
for i=a:b
p=p+1;
x(p)=i;
y(p)=24*sin(10*i)+2*(i^2)+4 ; %Change here for different function
end
l=length(x);
x
y
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.