Fitting two data sets with different equation but same parameters

16 views (last 30 days)
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

Accepted Answer

Shashank Prasanna
Shashank Prasanna on 8 Jul 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]);

More Answers (0)

Categories

Find more on Fit Postprocessing in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!