MATLAB HELP PLEASE Write a Matlab function that evaluates a sum of sines at a se
ID: 3604531 • Letter: M
Question
MATLAB HELP PLEASE
Write a Matlab function that evaluates a sum of sines at a set of points. The first term is just a constant (a coefficient with no sine term). Then, each sine term will have a coefficient before it and then an increasing multiple of the angle inside. For example, consider the sum 3 + 4 sin(9)-1.5 sin (20) 2 sin (40)3 sin (50) We recognize that this is the same as 344sin(101+-1.5 sin (20) + 0 sin (30) + 2 sin (40) +3 sin (50) And, the coefficient vector would be [3, 4, -1.5, 0, 2,3. Notice that there is no 30 term, so its coefficient is 0 The function should take two parameters. The first is a vector of coefficients corresponding to the coefficients of the terms of the sum. The second is the set of values for at which to evaluate the sum of sines. The function should return the set of output points of the polynomial evaluated at the input points values Hint: One way to write the function involves using nested loops an outer one that goes through the and an inner one at each 9that sums the sine values times the coefficients. As an example, here is the function called for the above sine series, then plotted. thetas = linspace (0,10); coefs = [3, 4, -1.5, 0, 2, -3); y = SineEval (coefs, the tas);Explanation / Answer
SineEval
_______________
function y=SineEval(coefs,thta)
y=coefs(1)+coefs(2)*sin(1*thta)-coefs(3)*sin(2*thta)+coefs(4)*sin(3*thta)+coefs(5)*sin(4*thta)-coefs(6)*sin(5*thta);//expresssion
end
mainscript
______________________
step=20/200;%stepsize for 200 evenly space input
thtas=0:step:20-step;%input array theta
coefs=[-1,1.25,-2.5,0,5,-10];%co-efficent array for fun
for j=1 : 200%calling SineEval 200 times for succesive thetas
y(j)=SineEval(coefs,thtas(j));%storing the results in y(i)
end
figure
plot(thtas,y);
grid on;
xlable('theta(rads)');
ylable('x(m)');
title('-1+1.25sin(2theta)+5sin(4theta)-10sin(5theta)')
show
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.