Question: MATLAB QUESTION: Based on the function P_inner (Below), make a new function: L = PolyLine(u,v) such that u and v are column (n+1) vectors. n

MATLAB QUESTION:

Based on the function P_inner (Below), make a new function:

L = PolyLine(u,v)

such that u and v are column (n+1) vectors. n will be an input in a script made when using this new function.

HINT: used vectorized arithmetic. If z is a length-5 vector, then:

alpha = sum (abs(z(1:4)-z(2:5)))

which asigns alpha = |z_1-z_3| + |z_2-z_3| + |z_3-z_4| +|z_4-z_5|

------

function P = P_inner(a,b,n) % a and b are the semiaxes of an ellipse E. % n is a positive integer bigger than 2. % P is the perimeter of the inner polygon whose % vertices are on E.

theta = 2*pi/n; innerSum = 0; % Sum the side lengths... for k=1:n % Coordinates of vertex k... xk = a*cos(k*theta); yk = b*sin(k*theta); % Coordinates of vertex k+1... xkp1 = a*cos((k+1)*theta); ykp1 = b*sin((k+1)*theta); % Add in the distance between them... dk = sqrt((xk-xkp1)^2 + (yk-ykp1)^2); innerSum = innerSum + dk; end P = innerSum;

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!