Problem 2: The curve shown in problem 1 is for the function y x There is no expr
ID: 3703364 • Letter: P
Question
Problem 2: The curve shown in problem 1 is for the function y x There is no expression for the indefinite integral of this function. However, we can estimate the definite integral using numerical integration as you have done in Problems 1. Write a MATLAB script that wll: Begin with 3 data points (x-values) evenly distributed from 0 to 3.6 inclusive (Hint: use the MATLAB command, linspace). Calculate the corresponding y-values for the function y-x*x. Estimate the integral of y from 0 to 3.6 using the Trapezoid Rule. Double the number of data points and get a new estimate for the integral of y from 0 to 3.6 using the trapezoid rule. Compare the new estimate to the previous estimate. If the absolute value of the difference between the two estimates exceeds 0.01, then double the number of data points again and repeat. Continue doubling the number of data points until the absolute value of the difference between the new estimate for the integral and the previous estimate for the integral does not exceed 0.01. Once your estimate has met the convergence specifications, add fprintf statements to display your final estimate of the integral, the final number of sections, and the final DeltaX value. PASTE Results of fprintf statements here: PASTE Script file here:Explanation / Answer
SAVE THE FOLLOWWING CODE IN MATLAB AND GE THE RESULTS-
clc
clear
close all;
%% Part (A)
x=linspace(0,3.6,3);
%% Part (B)
y=x.^x;
%% Part (C)
f=@(x)x^x; %Change here for different function
a=-3;
b=3; %Given limits
n=b-a; %Number of intervals
h=(b-a)/n;
p=0;
for i=a:b
p=p+1;
x(p)=i;
y(p)=i^4; %Change here for different function
end
%% Part (D) and (E)
new_x=linspace(0,3.6,6);
f=@(new_x)new_x^new_x; %Change here for different function
a_new=-3;
b_new=3; %Given limits
n_new=b_new-a_new; %Number of intervals
h_new=(b_new-a_new)/n_new;
p_new=0;
for i=a_new:b_new
p_new=p_new+1;
x_new(p_new)=i;
y_new(p_new)=i^4; %Change here for different function
end
%% Part (F) and (G)
diff=y-y_new;
fprintf('The Final value of the integral is %d ',y_new)
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.