Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Use a separate Matlab script to perform the following: Load the datasets, and plot them in separate figures using Matlab s scatter plotting function. Which

Use a separate Matlab script to perform the following:
Load the datasets, and plot them in separate figures using Matlabs scatter plotting function.
Which basis function is appropriate? (trig or poly)
Should you use approximation or interpolation? J
Use your func_fit function to perform both approximation and interpolation on the given datasets
Plot the approximator and interpolant with different colors on top of the scatter plot of each dataset.
data:(in test.txt)
X1=[1.1,2.2,3.3,4.4,0.5]
Y1=[0.1,1.2,2.3,3.4,4.5]
X2=[0.5,1.5,2.5,3.5,4.5]
Y2=[4.5,3.5,2.5,1.5,0.5]
funfit:
function [coefficient_vector]= func_fit(X,Y,type,basis,parameters)
if contains(type, 'approximate')
if contains(basis, 'poly')
m = parameters;
X_design = ones(length(X), m+1);
for i =1:m
X_design(:, i+1)= X.^i;
end
results = X_design' * X_design;
results = results \(X_design' * Y);
coefficient_vector = results;
return
elseif contains(basis, 'trig')
X_trig =[sin(X), cos(X)];
result2= X_trig' * X_trig;
result2s = result2\(X_trig' * Y);
coefficient_vector = result2s;
return
end
elseif contains(type, 'interpolate')
if contains(basis,'poly')
x_transpose = X';
result = x_transpose * X;
results = result \ x_transpose * Y;
coefficient_vector = results;
return
elseif contains(basis, 'trig')
X_trig =[sin(X), cos(X)];
result1= X_trig' * X_trig;
result1s = result1\(X_trig' * Y);
coefficient_vector = result1s;
return;
end
end
end

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions