Fitting two data sets with different equation but same parameters
15 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hi everyone,
I have a problem on my hands that I don't really know how to solve. I have two sets of data, one is Amplitude vs Temeprature (let's called it Amp vs Temp) and another is Phase vs Temperature (say Phi vs Temp). Right now I need to fit a non-linear model to Amp vs Temp, let's say for simplicity
Amp(Temp) = a*Temp^2+b*Temp^3, a
nd a different model to Phi vs Temp, let's say
Phi(Temp) = a*exp(-b*Temp).
But a and b are the same for both Amp and Phi because they are actual physical quantities. How should I proceed?
Thank you very much!
Jennifer
0 commentaires
Réponse acceptée
Shashank Prasanna
le 8 Juil 2013
Jennifer, essentially you are solving a system of equations. Do you have the optimization toolbox? If you do then you can solve this either using fsolve or lsqnonlin
Create a function as follows:
function y = nonlinmodel(x,Temp,Amp,Phi)
y = [Amp - x(1)*Temp.^2 + x(2)*Temp.^3; Phi - x(1)*exp(-x(2)*Temp)];
% Where x(1) = a, and x(2) = b
Now you want to find x(1) and x(2) that minimizes the above system in a least square sense.
Temp = randn(100,1);
Amp = randn(100,1);
Phi = randn(100,1);
% Some random data for demonstration
f = @(x)nonlinmodel(x,Temp,Amp,Phi);
optimal_x = lsqnonlin(f,[0;0]);
% OR
optimal_x = fsolve(f,[0;0]);
2 commentaires
Shashank Prasanna
le 8 Juil 2013
Here are links to the documentation page of lsqnonlin and fsolve:
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Fit Postprocessing dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!