Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I need help with this MATLAB code. Please and thank you. Write a Matlab function

ID: 3604902 • Letter: I

Question

I need help with this MATLAB code. Please and thank you.

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(8-1.5 sin (20) + 2 sin (40-3 sin (50) We recognize that this is the same as 3+4 sin(10)+-1.5 sin (29)+0 sin (30)+2 sin (49)+ -3 sin (59) And, the coefficient vector would be [3, 4, 1.5, 0, 2, 3]. Notice that there is no 39 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. Hint: One way to write the function involves using nested loops - an outer one that goes through the values and an inner one at each that 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, thetas)

Explanation / Answer

SineEval.m has the function which takes coefs and thetas as input and finds the
output points for each theta according to the formula given.

main.m
creates 200 evenly spaced points of theta, creates a coefs vector and then plots the input and output.
The output of plot is shown below.
If you have further queries. Kindly comment.
*******************************************************************
SineEval.m

function output=SineEval(coefs,thetas)
    for i=1:length(thetas)
        output(i)=coefs(1);
        for j=1:length(coefs)-1
        output(i)=output(i)+(coefs(j+1)*sin(j*thetas(i)));
        end
    end
end

main.m


thetas = linspace(0,20,200);
coefs = [-1,1.25,-2.5,0,5,-10];
y=SineEval(coefs,thetas);
plot(thetas,y);
title('Plot of Sine function')
xlabel('theta (rads)') % x-axis label
ylabel('x (m)') % y-axis label

****************************************************************************

Output plot:


****************************************************************************
I hope this helps you.
If you find my answer helpful,
Kindly rate the answer.
All the best :)