Clear Filters
Clear Filters

How to write the codes to find out constants a,b and c;by using inside the best fit with y=b+c*exp(a*t)

2 views (last 30 days)
For example, you are given y=20,t=25. So it means that "20=b+c*exp(a*25)". If you could write the best fitting numbers, and the Matlab code to get it, that would be perfect, since i am a new starter for Matlab.
  1 Comment
Mathias
Mathias on 26 Sep 2011
The way you present the equation, it has 3 parameters: you can't decide them uniquely with only one equation. E.g. [a,b,c]=[0,0,20] and [a,b,c]=[1,20,0] are both exact solutions to the equation with y=20, and t=25. More generally [a,b,c]=[0,y,0] fits for any choice of t and y.
You need to specify the problem further for it to have unique solutions.

Sign in to comment.

Answers (2)

Grzegorz Knor
Grzegorz Knor on 26 Sep 2011

UJJWAL
UJJWAL on 26 Sep 2011
Hi Cihan,
You want to do it programmatically and it can be done but being a new user you may find it a bit difficult. There is a curve fitting toolbox in MATLAB which can be used by you. I am just describing it below for you.
a) Open the curve Fitting toolbox.
b)click on DATA...
c) Select the variables in the workspace that represtn the x and y-axis data and then click on create new data set.
d) Now Click on Ok and then click on Fitting... which is next to Data...
e) In the Type of Fit combo box select Custom Equations and then click on New.
f)A New window will open and there select the tab corresponding to General Equations.
g) Corresponding to the dependent variable y type the equation like cos(a*x+b).
h) As you will write the constants like a and b they will appear in the table below. You can also modify their starting points and their upper and lower limits. If you have any idea of these quantities depennding upon the nature of your program and your requirements then change them accordingly or let MATLAB handle the issue. It will just take some extra time.
Now CLick ok to go back to the previous window.
i) Click on Apply. MATLAB will compute the appropriate values of the constants and display them in the same wiundow under the title results. It will show the values of the constants you have provided computed in the least squares sense.
If you need more explanation ask further. However I think it will help you. If you are particular about the coding then after doing the fitting Click on File and Click on Generate Code. It will generate the code and then you would be able to see that it is a bit cluttered to do it programmatically. Good Luck to you.
Happy to Help
UJJWAL

Community Treasure Hunt

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

Start Hunting!