I\'m new to matlab, so I need help with this question Given below is the data yo
ID: 3637807 • Letter: I
Question
I'm new to matlab, so I need help with this question
Given below is the data you need for this problem.
% x y
%
0.0000000e+00 1.0616627e+00
2.0000000e-01 9.5438313e-01
4.0000000e-01 6.4726669e-01
6.0000000e-01 2.4543142e-01
8.0000000e-01 8.6474234e-03
1.0000000e+00 -4.5847332e-01
1.2000000e+00 -5.8629116e-01
1.4000000e+00 -5.2270060e-01
1.6000000e+00 -6.6897708e-01
1.8000000e+00 -6.5025323e-01
2.0000000e+00 -3.6829629e-01
2.2000000e+00 -1.9946104e-01
2.4000000e+00 1.0214847e-01
2.6000000e+00 2.3939828e-01
2.8000000e+00 4.7441685e-01
3.0000000e+00 5.3204202e-01
3.2000000e+00 4.8645531e-01
3.4000000e+00 3.8277756e-01
3.6000000e+00 2.7859469e-01
3.8000000e+00 9.5304196e-02
4.0000000e+00 -6.1937557e-02
4.2000000e+00 -1.6264995e-01
4.4000000e+00 -3.3465224e-01
4.6000000e+00 -3.7848057e-01
4.8000000e+00 -3.2684557e-01
5.0000000e+00 -3.0202142e-01
5.2000000e+00 -2.4418751e-01
5.4000000e+00 -1.2606921e-02
5.6000000e+00 4.2709432e-02
5.8000000e+00 7.1364914e-02
6.0000000e+00 1.9256373e-01
6.2000000e+00 2.2975779e-01
6.4000000e+00 1.0651973e-01
6.6000000e+00 1.0873230e-01
6.8000000e+00 1.6313790e-02
7.0000000e+00 8.2753168e-02
7.2000000e+00 -5.6705147e-02
7.4000000e+00 -5.6552321e-02
7.6000000e+00 -1.2417349e-01
7.8000000e+00 -1.4140695e-01
8.0000000e+00 -1.8606224e-01
8.2000000e+00 -1.0253530e-01
8.4000000e+00 -1.3337982e-01
8.6000000e+00 -4.7083796e-02
8.8000000e+00 8.5379099e-03
9.0000000e+00 9.3244738e-02
9.2000000e+00 1.8795176e-02
9.4000000e+00 4.5569780e-02
9.6000000e+00 1.1312777e-01
9.8000000e+00 1.5024618e-01
1.0000000e+01 5.9238496e-02
%
These data contains a set of data points (x(i), y(i)), i=1,2,...,N. The distance between the data and the fitting function f(x)=exp(-c*x)*cos(2*x) is defined as
dd(c)=sqrt(sum of (f(x(i))-y(i))^2).
Calculate dd(c) for c in [0,1]. Plot dd(c) as a function of c. Use about 100 points to represent dd(c).
Hint: in Matlab, dd(c)=sqrt(sum of (f(x(i))-y(i))^2) is implemented by
y2=exp(-c*x).*cos(2*x);
dd=norm(y2-y);
You need to do this for each value of c!
Explanation / Answer
Here are your codes. I have made two files, one for the function f(x) and the other for your program. Codes for the function f(x) ------------------------------------ function f = f(c,x) f=exp(-c*x)*cos(2*x); Codes for main program ---------------------------------- s=load('matlab_help.txt'); c=1; for i=0:.01:1 cdata(c)= i; sm=0; len=size(s) for j=1:len(1,1) sm= (f(i,s(j,1))-s(j,2))^2+sm; end dd(c) = sqrt(sm) c=c+1; end plot(cdata,dd); I hope this helps you.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.