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

I wrote a program using matlab that finds the intersection points for 2 polar cu

ID: 3707575 • Letter: I

Question

I wrote a program using matlab that finds the intersection points for 2 polar curves ( r1=1+Cos(x) and r2=3cos(x) ), however I would like to ask the user to enter the curves to make this program more advanced and to use it for different curves ,these are the codes:

format short

x=0:pi/100:2*pi;

y1 = @(x) 3*cos(x);

y2 = @(x) 1+cos(x);

for k1 = 1:2*pi;

x0 = 1.04*k1;

xint(k1) = fzero(@(x) y1(x)-y2(x), x0);

end

figure(1)

polar(x,y1(x))

hold on

polar(x,y2(x))

polar(xint, y2(xint), 'pb')

hold off

xint(1)

--

is there a method to use input function that could work with for loop and fzero function ?

Explanation / Answer

You can use input and inline to take curve equations from user and convert them int inline functions, so that you can use them later for evaluating the values.

Below I have edited your code to include those two:

f1 = input('Give an equation in x: ','s');

f2 = input('Give an equation in x: ','s');

format short

x=0:pi/100:2*pi;

y1 = inline(f1,'x');

y2 = inline(f2, 'x');

for k1 = 1:2*pi;

    x0 = 1.04*k1;

    xint(k1) = fzero(@(x) y1(x)-y2(x), x0);

end

figure(1)

polar(x,y1(x))

hold on

polar(x,y2(x))

polar(xint, y2(xint), 'pb')

hold off

xint(1)