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

Please provide MATLAB code. 1. Create a function that fits an nth order polynomi

ID: 674506 • Letter: P

Question

Please provide MATLAB code.

1. Create a function that fits an nth order polynomial curve to given data. i.e.: [fx, a] = curvepoly(x,y,n)

where:
x = vector of input data (x-axis)
y = vector of input data (y-axis)
n = order of polynomial desired
fx = y-axis values on the curve fit corresponding to the x-values.
a = the polynomial coefficients found

2. Create a function that fits an exponential curve to given data. e.g.,
[fx, A, C] = curveexp(x,y)

where:
x = vector of input data (x-axis)
y = vector of input data (y-axis)
fx = y-axis values on the curve fit corresponding to the x-values.
A, C = the coefficients found for the form fx = C*exp(A*x)

Explanation / Answer

function [fx,a]=curvepoly(x,y,n)
x=x(:);
for i=0:n-1
m(:,n-i)=x.^i;
end
a=my;
fx=polyval(a,x);

2.code to Create a function that fits an exponential curve to given data. e.g.,
[fx, A, C] = curveexp(x,y)

function [E, M] = curveexp(x, y)

start_point = rand(1, 2);

M = @expf;

E= fminsearch(M, start_point);

         function [a,c, fx] = expf(params)

        C = params(1);

       A= params(2);

                fx = C*exp(A*x)

        ErrorVector = fx - y;

        c = sum(ErrorVector .^ 2);

    end

end

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote