MATLAB QUESTION: Given the following script, what is the code you would add to t
ID: 3167507 • Letter: M
Question
MATLAB QUESTION: Given the following script, what is the code you would add to this script that would place a green x marker on the zero values (as in the x-intercepts) of this plot?
% Script Eg4_1
% Plots the function f(x) = sin(5x)*exp(-x/2)/(1 + x^2) across [-2,3].
L = -2; % Left endpoint
R = 3; % Right endpoint
N = 200; % Number of sample points
% Obtain the vector of x-values and f-values...
x = linspace(L,R,N);
y = sin(5*x) .* exp(-x/2) ./ (1 + x.^2);
% Plot and label...
plot(x,y,[L R],[0 0],':')
title('The function f(x) = sin(5x) * exp(-x/2) / (1 + x^2)')
ylabel('y = f(x)')
xlabel('x')
Explanation / Answer
func=inline('sin(5*x).*exp(-x/2)./(1+x.^2)')
r=fsolve(func,[-2:0.01:2])
y_r=sin(5*r).*exp(-r/2)./(1+r.^2)
plot(r,y_r,'x')
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.