Question

In: Computer Science

(MATLAB Question) 1a. Establish a variable “x” that goes from -10 to 10 in increments of...

(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

Solutions

Expert Solution

% 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:


Related Solutions

Two processes share the variable "I". Process A increments it 10 times and process B decrements...
Two processes share the variable "I". Process A increments it 10 times and process B decrements it 25 times without using critical sections. The initial value of I is 0. The final value of I MUST be Please explain.
MATLAB QUESTION Write a python program to request a positive float input from the user, x....
MATLAB QUESTION Write a python program to request a positive float input from the user, x. The program should check for the value of x. If x is larger than or equal to 1.0, the program should display the value of x in addition to the string “is larger than or equal to 1” and then terminate the program. If x is less than 1 the program should calculate y such that: y = 1-x+x^2/2-x^3/3+x^4/4-x^5/5……-x^99/99+x^100/100 The program should then display...
assume that the data are stored in variable names x and y. write a matlab code...
assume that the data are stored in variable names x and y. write a matlab code to plot the quadratic spline and along with the data points x= 1 2 3 4 5 6 y= 40 78 125 256 348 425
Write your own MATLAB code to solve the system 10 − x + sin(x + y)...
Write your own MATLAB code to solve the system 10 − x + sin(x + y) − 1 = 0 8y − cos2 (z − y) − 1 = 0 12z + sin(z) − 1 = 0 using a residual tolerance of 10^−6 and the initial guess, ~x 0 = [0.1, 0.25, 0.08]^T . Print out the values for x, y and z for each iteration in a table similar to the one you created for the problems of the...
1. A.write a chemical equation which goes with the statement: i) Kb= 4.3 X 10-10 for...
1. A.write a chemical equation which goes with the statement: i) Kb= 4.3 X 10-10 for aniline (C6H5NH2) ii)Kb = 2.1 X 10-4 for carbonate ion B. Kb =1.3 X 10-3 for C5H11N and kb= 6.3 x 10-5 for N(CH3)3 i) Which base is the stronger base in water ii) For the same solute concentration, which base has the larger equilibrium OH- concentrations?How did you decide? C. Reaction of amide ion (NH2-), ethoxide ion (OCH2CH3-), methoxide ion (OCH3-), hydride ion...
The question is to use Matlab to find the clamped cubic spline v(x) that interpolates a...
The question is to use Matlab to find the clamped cubic spline v(x) that interpolates a function f(x) that satisfies: f(0)=0, f(1)=0.5, f(2)=2, f(3)=1.5, f'(0)=0.2, f'(3)=-1 and then plot v(x). This is my code so far: x = [0 1 2 3]; y = [0 0.5 2 1.5]; cs = spline(x,[0 y 0]); xx = linspace(0,3,101); figure() plot(x,y,'o',xx,ppval(cs,xx),'-'); IS THIS RIGHT? HOW CAN I GET MATLAB TO GIVE ME THE EQUATION OF v(x)?
1. Let X be a continuous random variable such that when x = 10, z =...
1. Let X be a continuous random variable such that when x = 10, z = 0.5. This z-score tells us that x = 10 is less than the mean of X. Select one: True False 2. If an economist wants to determine if there is evidence that the average household income in a community is different from $ 32,000, then a two-tailed hypothesis test should be used. Select one: True False 3. α (alpha) refers to the proportion of...
Please show MATLAB code to plot below function from x = −3 to x = 12:...
Please show MATLAB code to plot below function from x = −3 to x = 12: function f = piecewise(x) % implements piecewise function using if statements if x < 0     f = -x^3 - 2*x^2 + 3*x; elseif x <= 8     f = (12/pi) * sin(pi*x/4); else     f = (600*exp(x-8))/(7*(14 + 6*exp(x-8))) -30/7; end
A random variable Y is a function of random variable X, where y=x^2 and fx(x)=(x+1)/2 from...
A random variable Y is a function of random variable X, where y=x^2 and fx(x)=(x+1)/2 from -1 to 1 and =0 elsewhere. Determine fy(y). In this problem, there are two x values for every y value, which means x=T^-1(y)= +y^0.5 and -y^0.5. Be sure you account for both of these. Ans: fy(y)=0.5y^-0.5
question should be done on Matlab 4) Find the derivative of sin(2x) at x = 0.8...
question should be done on Matlab 4) Find the derivative of sin(2x) at x = 0.8 rad and find the value of h where the error is minimum as compared to the true value i.e. actual value or accurate value. a) Use for loop b) Use element by element operation
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT