curve fitting with fminsearch
94 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Burak Akayoglu
le 18 Mai 2020
Commenté : Burak Akayoglu
le 18 Mai 2020
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 commentaires
Ameer Hamza
le 18 Mai 2020
Modifié(e) : Ameer Hamza
le 18 Mai 2020
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?
Réponse acceptée
Ameer Hamza
le 18 Mai 2020
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), '-')
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/293923/image.png)
3 commentaires
Ameer Hamza
le 18 Mai 2020
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.
Plus de réponses (1)
Ang Feng
le 18 Mai 2020
Hi Burak,
This link is certainly helpful
Matlab has very good documentation.
Good luck
Voir également
Catégories
En savoir plus sur Solver Outputs and Iterative Display dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!