We are asked to use Matlab MATLAB Matlab Consider a ball sh

We are asked to use Matlab #MATLAB #Matlab
Consider a ball - shape model: (x - a)^2 + (y - b)^2 + (z - c)^2 = r^2 where (a, b, c) is the center and r is the radius. We can transform this model into a linear one by noting that: Write a function my Fit: output = my Fit (X), where X is an 3-by-n dataset matrix, with each column is a dataset. method: 1 for using the above transformation method, 2 for using the \"fminsearch\" method. output: a column vector of the derived [a, b, c, r]*. (where * indicates optimal values). J (X: a, b, c, r) = sigma^n_i = 1 (||x_i - [a, b, c]|| - r)^2, where x_i, is the itch column of the dataset matrix X. Please generate a ball dataset with r = 10, a = b = c = 1, and add zero-mean unit-variance Gaussian noise into it. Please use my Fit to derive the model parameters. Write down the derived model mathematically. Last, please visualize the resulting model along with sample points using a figure.

Solution

rng default
%declaring limits
xdata = 0:0.1:1;
Ydata = 30*exp(-0.3*xdata) + randn(size(xdata));

function res = sseval(t,xdata,Ydata)
   P = t(1);
   lambda = t(2);
   res = sum((Ydata - P*exp(-lambda*xdata)).^2);

fun = @(t)sseval(t,xdata,Ydata);
p0 = rand(2,1);
bestx = fminsearch(fun,p0)
P = bestx(1);
lambda = bestx(2);
yfitVal = P*exp(-lambda*xdata);
plot(xdata,Ydata,\'*\');
hold on
plot(xdata,yfitVal,\'r\');
xlabel(\'xdata\')
ylabel(\'Result data\')
title(\'Best Fitting\')
legend(\'Given data\',\'fitted-Curve\')
hold off

We are asked to use Matlab #MATLAB #Matlab Consider a ball - shape model: (x - a)^2 + (y - b)^2 + (z - c)^2 = r^2 where (a, b, c) is the center and r is the rad

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site