Write a Matlab script using the trapezoidal method to calculate the area under t
ID: 3771497 • Letter: W
Question
Write a Matlab script using the trapezoidal method to calculate the area under the curve given by the enclosed velocity profile data in the attached matlab file Prob2-3.mat. The velocity is fitted by the following equation:
Calculate the relative error for the solution of trapezoidal full step 2*h, trapezoidal half step h and the 6th order accurate Richardson method. The three relative errors will be evaluated by using the analytical solution resulting from the integration the above equation from -15 <= y <= 15.
Ux Uy -5.00E-05 15 0.000112 14 0.000247 13 0.000372 12 0.000487 11 0.000593 10 0.000688 9 0.000773 8 0.000848 7 0.000913 6 0.000968 5 0.001013 4 0.001048 3 0.001073 2 0.001088 1 0.001093 0 0.001088 -1 0.001073 -2 0.001048 -3 0.001013 -4 0.000968 -5 0.000913 -6 0.000848 -7 0.000773 -8 0.000688 -9 0.000593 -10 0.000487 -11 0.000372 -12 0.000247 -13 0.000112 -14 -5.00E-05 -15Explanation / Answer
We can use the trapezoidal method to find the area under the curve. First we need to read the file and then load the file values of the file into a array. Now based on that we can use the trapz function in matlab to find the area.
dat=load("input.txt");
X=dat(:,1);
Y=dat(:,2); % now with this X will contain all the x coordinates of the file and Y will have all the Y coordinates.
X=max(X,0); % for negative numbers present in X
Y=max(Y,0); % for negative numbers present in Y
area = trapz(X,Y);
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.