curve fitting with fminsearch

조회 수: 158 (최근 30일)
Burak Akayoglu
Burak Akayoglu 2020년 5월 18일
댓글: Burak Akayoglu 2020년 5월 18일
Hello all,
I'm trying to learn MATLAB and take a course for that, and i have a homework that i can't solve. I have experimental datas for x and y variables(total 11 each) and the question asks me to fit the datas by using 'fminsearch' .
Can anyone help me how can i find the best curve and write a proper code? Thank you
x=[3, 5, 7, 10, 13, 17, 20, 23, 25, 29, 31];
y=[1.1 , 2.0 , 3.7 , 9.0 , 22.2 , 73.8 , 181.5,446.5 , 813.6 , 2701.3 , 4922.1];
  댓글 수: 2
Ameer Hamza
Ameer Hamza 2020년 5월 18일
편집: Ameer Hamza 2020년 5월 18일
Can you show what you have already tried? Even if you don't have a code, can you write down your understanding about solving this problem?
Burak Akayoglu
Burak Akayoglu 2020년 5월 18일
Well, i've tried to write those, but i know it's false.
In the question, x vs y datas are going to be fitted a curve (i think it's gonna be y= a*exp(bx) ) by using fminsearch, and find the parameters. I did it by using "cftool" but i couldnt do it with fminsearch. It would be great if you tell me how can i do that? thanks
f=@(x) a*exp(b*x);
x0=[2,1];
options = optimset('PlotFcns',@optimplotfval, 'Display','iter');
x = fminsearch(f,,x0,options)

댓글을 달려면 로그인하십시오.

채택된 답변

Ameer Hamza
Ameer Hamza 2020년 5월 18일
Study this example
x = [3, 5, 7, 10, 13, 17, 20, 23, 25, 29, 31];
y = [1.1 , 2.0 , 3.7 , 9.0 , 22.2 , 73.8 , 181.5,446.5 , 813.6 , 2701.3 , 4922.1];
f = @(a,b,x) a*exp(b*x);
obj_fun = @(params) norm(f(params(1), params(2), x)-y);
sol = fminsearch(obj_fun, rand(1,2));
a_sol = sol(1);
b_sol = sol(2);
figure;
plot(x, y, '+', 'MarkerSize', 10, 'LineWidth', 2)
hold on
plot(x, f(a_sol, b_sol, x), '-')
  댓글 수: 3
Ameer Hamza
Ameer Hamza 2020년 5월 18일
That a very useful observation. Many times differences in scale of the data points also make it difficult for optimizers to find an optimal solution. Such modifications can make things easy for the optimizer.
Burak Akayoglu
Burak Akayoglu 2020년 5월 18일
Thankyou very much Ameer and John. Your answers help me a lot both solve the question and understand the concept. Thank you for your time and effort again.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Ang Feng
Ang Feng 2020년 5월 18일
Hi Burak,
This link is certainly helpful
Matlab has very good documentation.
Good luck
  댓글 수: 1
Burak Akayoglu
Burak Akayoglu 2020년 5월 18일
Hi Ang,
Thanks for your answer. I will check this documentation

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Solver Outputs and Iterative Display에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by