Question
This uses MATLAB code with plotting
HW19: Plotting with plot () Due 11:59 pm Monday 1. (10 pts) Write a script that will produce a sine curve and a cosine curve in the same plot, 0 as shown to the right. 06 0.4 0.2 To have two sets of data in one plot, you may plot the first one, then with the command hold on, plot the other. Or, you can learn how to plot two lines with just one plot () command. 02 The help document for the legend0 function will teach you how to set the location of legend box. -04 0.8 To modify x-axis, use: set (gca, XTick, 0:pi/2:2*pi) set (gca, XTickLabel,,pi/2,pi, 3pi/2, 2pi) 2. (20+10 pts) Write a programmer-defined function that will plot a circle with user-provided center and radius. The function definition should be in this format: function draw_circle lastname (x0, yo, R) where (x0, y0) is the coordinate of the center of the circle, and R is the radius of the circle. Note that the function does not return any variable 12 10 Also write a main program that prompts the user for x0, y0, and R, validate them, and call 6 the function to create the circle plot. Origin (5, 3) * Radus 10 For example, a function call of draw circle (5, 3, 10) will create this plot: -2 A few tips: As shown in the class example, you may set the angles spaced evenly, and let x and y be functions of this angle. - 10 15 - Use the function sprintf ) to create a customized string, and then call the text ) function to add that string to the proper place in the plot. Use axis equal to make x-axis and y-axis the same scale.
0 0
Add a comment Improve this question Transcribed image text
Answer #1

1)

x = [0:0.05:2*pi];
y1 = sin(x);
y2 = cos(x);
plot(x,y1,'b-o');
hold on;
plot(x,y2,'r-o');
legend('sin(x)','cos(x)','Location','southwest');
set(gca,'XTick',0:pi/2:2*pi);
set(gca,'XTickLabel',{'0','pi/2','pi', '3pi/2','2pi'});

FILE EDIT calc.mHW19... draw.plotcir...x 0.8 0.6 0.4 0.2 2- y1=sin(x); 3y2cos (x) 4-plot (x,yl, b-o) hold on 6plot (x, y2, r-0) 7legend(sin (x,cos (x), Location, southwest) 8- set (gca , XTick , 0: pi/2:2*pi); 10 0.2 0.4 0.6 cos(x) pi/2 pl 3pi/2 2pi

2)

function draw_circle_lastname( x0,y0,R )

th = 0:pi/50:2*pi;
X = R * cos(th) + x0;
Y = R * sin(th) + y0;
H = plot(X, Y);
hold on;
scatter(x0,y0,'r.'); % plot center
str = sprintf('Origin(%d,%d)\n Radius %d',x0,y0,R);
  
text(x0,y0,str);
axis equal;
hold off;
end

plotcircle.m

fprintf('Enter center of circle\n');
x0 = input('x0: ');
y0 = input('y0: ');
R = input('Enter Radius of Circle: ');
draw_circle_lastname(x0,y0,R);

Add a comment
Know the answer?
Add Answer to:
This uses MATLAB code with plotting HW19: Plotting with plot () Due 11:59 pm Monday 1....
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Please show the code necessary, and explanations on MATLAB. Plotting 11) Plot the function y =...

    Please show the code necessary, and explanations on MATLAB. Plotting 11) Plot the function y = sin(x) from x = 0 to 21. 12) Plot the functions y = x2 z = x2 + 2x + 1 from x = 0 to 2 on the same graph. Scripts: Input and Output 13) Write a script (M-file) to read in a message at the command line using the MATLAB input function and then display the message to the Command Window using...

  • Please use matlab cars. Answer: Function file; Command Window: 5.4 Write a user-defined function that plots...

    Please use matlab cars. Answer: Function file; Command Window: 5.4 Write a user-defined function that plots a circle given the coordinates of the center and the radius. For the function name and arguments use circleplot(x,y,R). The input arguments are the and y coordinates of the center and the radius. Use linspace to generte the angle from 0 to π with 100 points. (Hint: the circle equation: x+Rcos and yy-yRsin 0.) This function has no output arguments. Plot the circle using...

  • In this exercise, you will create a function trough_plot which will plot the cross-section of a...

    In this exercise, you will create a function trough_plot which will plot the cross-section of a trough outlines by the functions y0 and y. Input variables: x – a vector representing the x co-ordinates for the outline of the trough. y – a vector representing the y co-ordinates for the bottom of the trough. y0 – a vector representing the y co-ordinates for the top of the trough. Output variable: n/a – this function has no output variables. Process: The...

  • CS240 Intro Engineering Programming Programming Assignment # 6 Due Friday, March 29th by midnight Topics: Plot...

    CS240 Intro Engineering Programming Programming Assignment # 6 Due Friday, March 29th by midnight Topics: Plot subplot We know that the work done by a force F which is applied on a box at an angle x-axis and a displacement value d is given by: with respect to the and assume we know that d 15 m. Write a function its name is "work calculator" which gets two inputs 1) A vector which includes angle( θ ) values ranges from...

  • Write a MATLAB Graphical User Interface (GUI) to simulate and plot the projectile motion – the...

    Write a MATLAB Graphical User Interface (GUI) to simulate and plot the projectile motion – the motion of an object projected into the air at an angle. The object flies in the air until the projectile returns to the horizontal axis (x-axis), where y=0. This MATLAB program should allow the user to try to hit a 2-m diameter target on the x-axis (y=0) by varying conditions, including the lunch direction, the speed of the lunch, the projectile’s size, and the...

  • Please help me with this MATLAB programming problem! Im coding iin MATLAB2018 if that makes any d...

    Please help me with this MATLAB programming problem! Im coding iin MATLAB2018 if that makes any difference! The first picture is the question i need to answer. The picture below is used as reference to answer the question. The last picture (below) is the into to the problem, and is used as reference. 1. Use Matlab to create the following single plot with three subplots. All titles, gridlines, and axis labels should be as shown. Arc System Response 15 E...

  • please help me with this MATLAB CODE and explain to me what each line does and...

    please help me with this MATLAB CODE and explain to me what each line does and what is used for? leave your comments as words, not as pictures. ..................................................................................................................................................................... clear all; close all; % For a script file, you better start with clear all and close all                        % However, for a fucntion, you better NOT to start                        % with them %% End of cell mode example %% Plot function t = 0:0.1:5; x1 = sin(2*5*t); x2 = cos(3*7*t);...

  • USE MATLAB ALSO PLOT THE PENDULUM animation Case 1: Pendulum Create a plot that shows a...

    USE MATLAB ALSO PLOT THE PENDULUM animation Case 1: Pendulum Create a plot that shows a pendulum moving. First,use the ode45 function to solve the pendulum equation between 0 and 10 seconds. The pendulum equation is: Create a plot that shows a pendulum moving First, use the ode45 function to solve the pendulum equation between 0 and 10 seconds. The pendulum equation is: + sin(e) 0 where g is gravity and L is the length of the pendulum bar. Use...

  • Please help with this MATLAB problem! I'm writing in MATLAB_R2018b if that makes a difference:) 7....

    Please help with this MATLAB problem! I'm writing in MATLAB_R2018b if that makes a difference:) 7. Write a Matlab function (HW07 07.m) that takes 4 arguments and returns two arrays. The arguments are the Xc and yc coordinates of the center of a circle, the radius r of the circle, and the number of points n on the circle. The function should create a list of n equally-spaced angle values ranging from 0 to 2n. Then, for each angle value,...

  • Create a code that performs the following actions: l. Define the flow rate and height of tank 2./ Have the user input a value for radius 3./ Ask the user for a value of many minutes the tan...

    Create a code that performs the following actions: l. Define the flow rate and height of tank 2./ Have the user input a value for radius 3./ Ask the user for a value of many minutes the tank should fill for 4. Clear the command window (clc) after all of the input commands are given 5. Call in a "tank solver" function that performs the following Takes F, h, r, and t final as inputs, and there are no variable...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT