we are required to use matlab for this question.this is what i already tried: fu
ID: 3781575 • Letter: W
Question
we are required to use matlab for this question.this is what i already tried:
function[output] = myFit(X)
a=1;
b=1;
c=1;
r=10;
X=zeros(3,10000);
i=1;
for theta = linspace(0,2*pi,100)
for phi = linspace(0,pi,100)
X(:,i)=[a+r*cos(theta)*cos(phi),b+r*sin(theta)*cos(phi),c+r*sin(phi)]';
i=i+1;
end
end
X=X+randn(size(X));
x=X(:,1);y=X(:,2);z=X(:,3);
A =[x y z ones(size(X(:,1)))];
b=x.^2+y.^2+z.^2;
theta=A;
a=theta(1)/2; b=theta(2)/2;c=theta(3)/2;
r=sqrt(theta(4)+a.^2+b.^2+c.^2);
output=[a b c r];
end
how to vizualize?
2) (5%) Consider a ball-shape model: a)2 (y b)2 (z where (a, b, c) is the center and r is the radius. We can transform this model into a linear one by noting that: 2a 2b (z,y, 2,1] 2c 2- a2-b2 c2 Write a function myFit 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 la, b, c, r] (where indicates optimal values) Note that when "fminsearch" is used, the objective function should be defined as follows: J(X; a, b, c, r) ai [a, b, c ix-1 where ai is the ith 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 myFit to derive the model parameters. Write down the derived model mathematically. Last, please visualize the resulting model along with sample points using a figure.Explanation / Answer
MATLAB has several functions for 3D Visualization :
eg.
x = linespace ( from , to , points to use );
y = linespace ( from , to , points to use )
z = in terms of x,y ,a,b,c,R as mentioned in problem above
You can use any of the following as per need
plot3(x,y,z)
comet3(x,y,z)
mesh(x,y,z)
surf(x,y,z)
You may like to use other version surfc ,surfl , meshz .
Or
Change colour of visualization :
colormap('jet') .. there are several options jet, winter , spring etc.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.