In: Computer Science
(MATLAB Question)
1a. Establish a variable “x” that goes from -10 to 10 in increments of .1
1b. Create an equation of a line (y=mx+b) based on “x” with slope m=2 and y-intercept 2. (y=2x+2)
1c. Plot the line (plot(x,y)).
1d. Turn on a plot hold (hold on).
1e. Create a second equation of a line (y=mx+b) based on “x” with negative slope, slope m=-2 and a negative y-intercept -2. (y=-2x-2)
1f. Plot the second line (plot (x,y))
1g. Create a quadratic equation for y. y=-4x2+4x+4 (y=-4*x.^2+4*x+4) (Use .^ for the squared command)
1h. Plot the quadratic (plot(x,y))
1i. Turn hold off (hold off)
This is my final product. The graph screen appears with no graph and not sure what I'm missing.
x = [-10,.1,10] %Variable "x" that goes from -10 to 10 in increments of .1
m = 2; %slope
b = 2; %intercept
x = -10;10; %value range for x, plotting 10 points in range -10 to 10
y = m*x+b; % equation of line
plot(x,y); %plot the graph for x and y
hold on %hold on the graph
m = -2; %slope
b = -2; %intercept
x = linespace(-10,10,10); %value range for x
y = m*x+b; %equation of line
plot(x,y); %plot the graph for x and y
y=@(x)-4*x.^2+4*x+4; % quadratic equation
%plotting the function
x=0:0.1:10;
plot(x,y)
hold off
% Matlab script to plot multiple graphs in a single plot
x = (-10:0.1:10); %Variable "x" that goes from -10 to 10 in
increments of .1
m = 2; %slope
b = 2; %intercept
y = m.*x+b; % equation of line
plot(x,y); %plot the graph for x and y
hold on; %hold on the graph
m = -2; %slope
b = -2; %intercept
y = m*x+b; %equation of line
plot(x,y); %plot the graph for x and y
y= -4.*x.^2+4.*x+4; % quadratic equation
%plotting the function
plot(x,y);
hold off;
xlabel('x');
ylabel('y');
%end of script
Output: