Question

In: Computer Science

In MATLAB: (a) Insert a comment in your script that says Problem 1: (b) Below this...

In MATLAB:

(a) Insert a comment in your script that says Problem 1:

(b) Below this comment, generate a vector of values called x that starts at −10, ends at 8, and has a step size of 0.1 between points.

(c) Define the function f(x) = (x − 6)(x 2 − 1)(x + 8) in your script, then plot f(x) against x.

(d) Plot the x- and y-axes on the plot in part (c). Mark each of the x-intercepts on this plot (you will need the hold on command).

(e) Label the x- and y-axes (you will need the xlabel and ylabel commands).

Solutions

Expert Solution

% Problem 1:

% Matlab script to calculate and plot the function f(x) for given values of
% x and plot the x-intercepts points for this function
% define the vector x that starts from -10 and end at 8 with steps of 0.1
x = (-10:0.1:8);

%define the function
f = @(x) (x-6).*((x.^2)-1).*(x+8);

y = f(x); % calculate the value of f at x points

plot(x,y); % plot y vs x
hold on; % used to plot in the same graph

% find is used to return the indices corresponding to the entries
% satisfying the given condition
% Here it will return the indices of y vector where value of function is 0
I = find(y==0);

% plot x-axes and y-axes

xL = xlim; % get the x limits for the current axes
yL = ylim; % get the y limits for the current axes

line([0 0],yL); % plot y-axis
line(xL,[0 0]); % plot x-axis

%plot the x-intercepts with red circles
plot(x(I),y(I),'ro');
hold off; % release the current plot
xlabel('x'); % label the x-axes
ylabel('f(x)'); % label the y-axes
% set the title
title('Plot of f(x) v/s x marking each of x-intercepts');
%end of script

Output:


Related Solutions

write matlab script of N channel MOSFET (Iv curve) will like and comment if done correctly...
write matlab script of N channel MOSFET (Iv curve) will like and comment if done correctly plesse
Use MATLAB to create a script which solves for problem 5.9 in the book (5.11 in...
Use MATLAB to create a script which solves for problem 5.9 in the book (5.11 in the 4th edition). Given are the equations for the moment, as a function of x, starting from the leftmost side of the beam with x=0 and ending at the other end of the beam with x=12. This piecewise function together makes up the moment equation for the beam given. 0 ≤ ? ≤ 3 ?(?) = 265? − 5.56?3 , 3 < ? ≤...
Use Matlab and write entier script Problem 1. Using the information above, find y(n) for all...
Use Matlab and write entier script Problem 1. Using the information above, find y(n) for all n between 1:N. y(tn)=mx(tn)+b+r(tn) y=mx+b Plot the points on a graph, without connecting them with a line.   Use a command like: plot( x, y, ‘.r’ ) Now we want to find the “best fit” solution.   As was mentioned before, this was defined in the prior exercise. (You may wish to read this to understand how the algorithm works.)   Use the MATLAB code below. You...
QUESTION 5 1.    Switch to insert mode, and then create a script that performs the following: •       Sets...
QUESTION 5 1.    Switch to insert mode, and then create a script that performs the following: •       Sets the environment for the script to bash •       Have at least two comment lines that state the purpose of the script •       Clear the screen •       Sends messages back to the screen informing the user of what he or she is seeing displayed on the screen •       Have the script perform the following: o   Show your home directory o   Show your current working directory o   Create a directory called demo, and...
Use Matlab and write entier script Problem 2. Generate the estimate (linear estimate) for y_est, and...
Use Matlab and write entier script Problem 2. Generate the estimate (linear estimate) for y_est, and plot(x , y_est). Use “hold on” and plot(x,y) and plot(x,y_est), so that you can see the result of the line and how it fits the data.   Does it look like it did a pretty good job? An estimate of the “residual error” is the sum of the squares of the difference between y and y_est. This is often denoted as r2. r2 = sum(...
Section B: Using the financial statements of XYZ Furnishings (below), comment on your interpretation of the...
Section B: Using the financial statements of XYZ Furnishings (below), comment on your interpretation of the financial health of the company. There is a maximum of 10 marks available for this section, four marks for your knowledge and understanding of the financial statements, four marks for your analysis and evaluation and 2 marks for your communication. Statement of Financial Position Assets Current Cash and equivalents 220 Trade receivables 8,420 Other receivables 10 Inventories 1,000 ST Investments 160 Non-Current Land and...
Instructions: 1. Solve the following problems in a MATLAB script. You will be allowed to submit...
Instructions: 1. Solve the following problems in a MATLAB script. You will be allowed to submit only one script, please work all the problems in the same script (Hint: careful with variables names) 2. Show your work and make comments in the same script (Use %). Please write your name in the first line of the scrip with % 3. It is OK to work with other students, but what you submit should be your own work – not something...
Instructions: 1. Solve the following problems in a MATLAB script. You will be allowed to submit...
Instructions: 1. Solve the following problems in a MATLAB script. You will be allowed to submit only one script, please work all the problems in the same script (Hint: careful with variables names) 2. Show your work and make comments in the same script (Use %). Please write your name in the first line of the scrip with % 3. It is OK to work with other students, but what you submit should be your own work – not something...
USING MATLAB Where indicated in the script below, write a function, called myflip, which accepts one...
USING MATLAB Where indicated in the script below, write a function, called myflip, which accepts one vector v (either a column or a row) and outputs the same vector v of the same dimensions, but with the values in reverse order (use MATLAB function flip()). In other words, v will be overwritten by its flipped version. In your function, you may only use length() and floor(). You only need one loop. %this code tests the function, myflip, which you will...
Write script in Matlab to solve 1. Y=Ax where X is of dimension n by 1...
Write script in Matlab to solve 1. Y=Ax where X is of dimension n by 1 and A is of dimension m by n. 2. C= A*B where A is of dimension m by p and B is dimension of p by n. So write matlab script to obtain Y and C in above problems.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT