PROBLEM #1 Write Matlab program that doing the following - Show a Menu to ask us
ID: 3597435 • Letter: P
Question
PROBLEM #1 Write Matlab program that doing the following - Show a Menu to ask user to select one of the following curves: Circle, Ellipse , Hyperbola, and Parabola - According to user selection , ask user to enter the needed data . Then, call a proper user defined function in order to calculate X and Y vectors (using parametric equations). - After getting X and Y vectors , call a user defined function to plot the curves using x and y. The user defined function should be as the following: CrcCal: the circle user defined function to calculate x and y for a given value of radius and center point (a, b) . The equations are: x=atr*cos (t), ya b+r*sin (t) , where OS te S2n ElpCal : the Ellipse user defined function to calculate x and y for a given value of the radiuses in X and Y direction (a b). The equations are: x = a 'cos (t) , Y = b*sin (t) , where ost s2n HypCal : the Hyperbola user defined function to calculatex and Y for a given value of a and b : Xr = acosh (t) Right Branch of Hyperbola yr = bsinh (t) Kl = --acosh (t) Left branch of Hyperbola yl = bsinh (t) where - n St Sn ParCal: the Parabola user function to calculate X and y for a given a : X-2 * at , y-at*t , where sts say - 1000000 stS1000000 Crvlt the user defined function to plot the needed curve given X and Y that calculated before In the main program, you should use a menu to allow user to choose an option, then , invoke correct function to calculate x and y Then , call the Crvlt function to plot the needed curve . You should ask user in the main program to input all needed parameters or data, not in the function. • The program should run continuously until user enters -1.Explanation / Answer
%main script
while 1
fprintf('1.Circle 2.Ellipse 3.Hyperbola 4.Parabola ')
i=input('Enter choice:');
switch i
case 1
r=input('Enter radius:');
a=input('Enter x coordinate of center point:');
b=input('Enter y coordinate of center point:');
[x,y]=CrcCal(a,b,r);
CrvPlt(x,y)
case 2
a=input('Enter radius in x direction:');
b=input('Enter radius in y direction:');
[x,y]=ElpCal(a,b);
CrvPlt(x,y)
case 3
a=input('Enter a:');
b=input('Enter b:');
[x1,y1,x2,y2]=HypCal(a,b);
CrvPlt(x1,y1)
hold on
CrvPlt(x2,y2)
case 4
a=input('Enter a:');
[x,y]=ParCal(a);
CrvPlt(x,y)
case -1
break
end
end
%%%functions
function [x,y]=CrcCal(a,b,r)
t=0:pi/100:2*pi;
x=a+r*cos(t);
y=b+r*sin(t);
end
function [x,y]=ElpCal(a,b)
t=0:pi/1000:2*pi;
x=a*cos(t);
y=b*sin(t);
end
function [xr,yr,xl,yl]=HypCal(a,b)
t=-pi:pi/1000:pi;
xr=a*cosh(t);
yr=b*sinh(t);
xl=-a*cosh(t);
yl=b*sinh(t);
function [x,y]=ParCal(a)
t=-100000:1:100000;
x=2*a*t;
y=a*t.*t;
function CrvPlt(x,y)
plot(x,y)
grid on
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.