I have an observed curve. By guessing the values of the constant A and B in the equation I can get a calculated curve. i want to optimize the calculated and observed curve such that I can get the precise values of A and B. How do I do it?
You are now following this question
- You will see updates in your followed content feed.
- You may receive emails, depending on your communication preferences.
An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Show older comments
dmdt=(pil*(10^(A+B/T))*sqrt(pressure_900))/lnreri
I have experimentally calculated dmdt versus time and got a decay plot. I already have the values of every other variable in the above equation except for A and B.
I want to guess an initial value for A and B and plot my calculated dmdt versus time.
Is there a way to optimize the calculated and observed cure such that I can find the values of A and B if I have multiple curves?
Accepted Answer
Star Strider
on 19 Jan 2016
If you have the Statistics Toolbox, use the nlinfit function, or the Optimization Toolbox lsqcurvefit function.
9 Comments
AluAl
on 19 Jan 2016
lsqcurvefit is for exponential equations. Can I use it for my equation mentioned above? If I can, then what is the objective function that they are asking in the tool box? Thank you
The lsqcurvefit function is for any function you want to use it to fit your data. In this equation:
dmdt=(pil*(10^(A+B/T))*sqrt(pressure_900))/lnreri
you state you want to estimate ‘A’ and ‘B’. What is your independent variable in it? (I assume the others are parameters you will pass to the function and are already defined.)
Alan Weiss
MATLAB mathematical toolbox documentation
AluAl
on 21 Jan 2016
Dear Mr Strider,
Yes, all the other parameters will be defined by me. A and B are unknowns and I have an approximate value which I will feed intially. How do I write the fitting function for lsqcurvefit for the formuala mentioned above? Thank you both!
I would write it as:
% MAPPING: b(1) = A, b(2) = B
dmdt_fcn = @(b,T) (pil.*(10.^(b(1)+b(2)./T)).*sqrt(pressure_900))./lnreri;
b0 = [3; 7]; % Choose Appropriate Initial Parameter Estimates
b_est = lsqcurvefit(dmdt_fcn, b0, T, dmdt); % Assumes ‘T’ Is Your Independent Variable And ‘dmdt’ Is Your Vector Of Dependent Variables
dmdt_est = dmdt_fcn(b_est, T); % Generate Estimated Values Of ‘dmdt’ From ‘T’ And Estimated Parameters
figure(1)
plot(T, dmdt, 'bp')
hold on
plot(T, dmdt_est, '-r')
grid
xlabel('T')
ylabel('dmdt')
I also vectorised ‘dmdt_fcn’. It may not be necessary to vectorise every operation, but it is always good practice (unless you know you are doing matrix operations rather than element-wise array operations).
AluAl
on 21 Jan 2016
Thank you so much Mr Strider. I did follow your program. Could you please explain why this error is popping up. All my variables are a single values except pressure_900 which is a range of values. Is that a problem?
Error using snls (line 47) Objective function is returning undefined values at initial point. lsqcurvefit cannot continue.
My pleasure.
That one of your parameters is a vector will cause problems, but that is not the one that is throwing the error you see.
You need to choose another set of initial parameter estimates. I have no idea what the exact problem is, but see if setting your initial parameter estimates to:
b0 = rand(2,1);
solves the problem.
As for one of your parameters being a vector, you will likely have to choose one value of ‘pressure_900’ each time you estimate your parameter estimates. The best way to do that is to put it into a for loop, and store the estimated parameters in a matrix indexed to the loop index in each iteration.
AluAl
on 27 Jan 2016
Thank you again. I was able to do it with just a single value for 'pressure_900'. I have another related question,I have the experimental data, where more sets of data of the same process(distance versus temperature) were collected. Now I would like to fit curve (probably with sumofsines) in Matlab, which would be optimized to all sets of data.
I know how to fit curve with “Matlab Curve Fitting Tool” to one data set, but I don’t know how to do it with more sets.
I want to do it simultaneously for all the data sets so that it produces one optimized model.
Thank you in advance!!
My data is attached!
My pleasure.
I do not have the Curve Fitting Toolbox, so I cannot help you with it. I would have to know the function you want to fit.
More Answers (0)
Categories
Find more on Choose a Solver in Help Center and File Exchange
Tags
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)