Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I should have iteration check and a single main script with 2 user-defined funct

ID: 3349459 • Letter: I

Question

I should have iteration check and a single main script with 2 user-defined functions and display the correct value in the command window.

The perimeter, P, of an ellipse is given by: T/2 where k Va-ba .y Write a user-defined MATLAB function that calculates the perimeter of an ellipse. For function name and arguments use P-EllipsePer (a,b), where a and b are the major and minor axes, respectively, and p is the perimeter. You will need to use the composite Simpson's 3/8 method for the integration. For the function name and arguments use I-Simpsons38 (Fun, a, b). Fun is a name for the function that is being integrated. It is a dummy name for the function that is imported into Simpson38. The integration function calculates the value of the integral in iterations. In the first iteration the interval [a,b] is divided into three subintervals. In every iteration that follows, the number of subintervals is doubled. The iterations stop when the difference in the value of the integral between two successive iterations is smaller than 0.1%. Use EllipsePer and Simpsons38 to solve the perimeter of ellipses given by. You will have 62 3 to create a PartlMain script to run the functions and show the result P in the MATLAB command window.

Explanation / Answer

%%%% Matlab function

function [I]=simpson3_8(f,a,b,n)
h=(b-a)/(n-1);
t=a:h:b;
fc=f(t);
sum=0;
for n=2:length(t)-1
    if mod(n-1,3)==0
        sum=sum+3*fc(n);
    else
        sum=sum+2*fc(n);
    end
end
I=3*h/8*(sum+fc(1)+fc(end));

end

%%%% Function %%%

function P = elipser (a,b)
k=sqrt(a^2-b^2)/a;
f=@(t) sqrt(1-k^2*sin(t).^2) ;
k=3;
a1=0;
b1=pi/2;
tol=0.001;
for n=1:100
   I(n)= simpson3_8(f,a1,b1,k);
   k=2*k;
   if n>2
       if ((I(n)-I(n-1))<tol)
           break;
       end
   end
end
P=4*a*I(end);
end

%%% test function

clc;
clear all;
close all;
format long
a=6;
b=3;
P= elipser(a,b)


OUTPUT:

P =

25.410644827245079