MATLAB Answers

Fitting an equation to a Sine Function with NonLinearModel.fit

2 views (last 30 days)
Wesley Brown
Wesley Brown on 4 Dec 2019
Commented: Wesley Brown on 7 Dec 2019
I am trying to fit an equation to a set of data that behaves like the sine wave. The data is graphed below:
I already tried using the "cftool" function in matlab but it did not have the equation I need.
I need to use the following equations:
y = a0 + a1*x + a2*sin(a3*x+a4)
y = a1*x + a2*sin(a3*x+a4)
y = a0 + a1*x + a2*sin(a3*x+a4) + a5*sin(a6*x+a7)
Does anyone know how to use "NonLinearModel.fit" in order to fit one of the above functions to the graphed data? The x and y matrices are listed below.
Thanks in advance!
x = [0
90
180
270
360
450
540
630
720
810
900
990
1080
1170
1260
1350
1440];
y = [0
0.00599999999997181
0.00999999999999091
0.00499999999999545
0.0029999999999859
0.0029999999999859
0.00999999999999091
0.0149999999999864
0.0159999999999627
0.0029999999999859
0.00399999999996226
0.00599999999997181
0.00199999999995271
0.0109999999999673
0.0129999999999768
0.00999999999999091
0.00399999999996226];

  0 Comments

Sign in to comment.

Accepted Answer

Stephan
Stephan on 5 Dec 2019
"...I already tried using the "cftool" function in matlab but it did not have the equation I need...."
Did you notice that you can take adcantage of the custom function in cftool? Have a read here:

  1 Comment

Wesley Brown
Wesley Brown on 7 Dec 2019
This is great! I can’t believe I didn’t see this.
Thank you!

Sign in to comment.

More Answers (0)

Sign in to answer this question.