Question: I need help fixing my MATLAB code, I got a 1 / 2 . Here are the instructions: General curve fitting with nlinfit Assume these

I need help fixing my MATLAB code, I got a 1/2. Here are the instructions:
General curve fitting with nlinfit
Assume these variables are already defined:
x_list - list of x values
Y_list - list of y values
x- single x value
Write a MATLAB code segment that uses nlinfit to determine the best fit curve for the points in X_list and Y_list according to this equation
y=1A+Bx+eCx
where A,B, and C are constants. Use initial guesses of A=1,B=2, and C=0.
Your results should be stored in a structure named fitData with the following fields:
A : determined coefficient A
: determined coeeficient B
: determined coefficient C
x : provided value of x
Y : value of your curve fit equation evaluated at x
Example Test Case:
clear all; clc; format compact; format short g;
X_list =[1,3,5,7,9];
Y_list =[4.1054,3.7485,5.4772,9.036,15.68];
x=12;
% your code for the submit to MATLAB box here
%6%%%%
fitData
Should display this result in the command window
fitData =
X: 12
Y: 37.338
A: 1.8003
B: 2.2001
C: 0.3
Your code should work for any set of starting values. Do not include test cases, clear all, etc as part of your submission.
My Code:
clear all; clc; format compact; format short g;
X_list =[1,3,5,7,9];
Y_list =[4.1054,3.7485,5.4772,9.036,15.68];
X =12;
fitData = struct();
y = @(b,x)1./b(1)+ b(2)./max(x, eps)+ exp(b(3).*x);
Initial_Coff =[1,2,0]; % A =1, B =2, C =0
New_Coff = nlinfit(X_list, Y_list, y, Initial_Coff);
Y_new = y(New_Coff, X);
fitData.X = X;
fitData.Y = Y_new;
fitData.A = New_Coff(1);
fitData.B = New_Coff(2);
fitData.C = New_Coff(3);
fitData
Result:
MATLAB results:
Start of test case 1
C =
1.800349252553742.200102119579330.300002531051947
fitData =
struct with fields:
X: 12
Y: 37.338
A: 1.8003
B: 2.2001
C: 0.3
checking answer
++++++++GOOD++++++++
End of test case 1
Start of test case 2
C =
6.09975.30.1991
fitData =
struct with fields:
X: 12
Y: 37.338
A: 1.8003
B: 2.2001
C: 0.3
checking answer
Output 1 does not match
End of test case 2
1 of 2 test cases corrects

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!