You are now following this question
- You will see updates in your followed content feed.
- You may receive emails, depending on your communication preferences.
I want to fit some data x and y to a specific equation f(x) and then estimate this fitted data as g(x)=1/f(x) ?
3 views (last 30 days)
Show older comments
x=[0,0.5,1,1.5,2,2.5];
y=[1,0.8,0.6,0.4,0.2,0];
F(x)= exp[(a*x^2)+(b*x)+c], where a,b,c are not known to me
after fitting this data to this equation i want to get g(x)=1/f(x). The picture attached below demonstrates what we are trying to do. Figure A shows x and y fitted to f(x) and figure B shows estimated g(x)=1/f(x).
Accepted Answer
Ameer Hamza
on 30 Apr 2018
fitFunction = fittype('exp(a*x.^2+b*x+c)');
coff = fit(x', y', fitFunction);
a = coff.a;
b = coff.b;
c = coff.c;
18 Comments
Walter Roberson
on 30 Apr 2018
Once you have the coefficients you can construct f(x) with a simple anonymous function and then define g = @(x)1./f(x)
j.D
on 30 Apr 2018
Edited: Walter Roberson
on 30 Apr 2018
Thanks for your guidance after your comments this is what i am doing but still getting some error, please guide
fitFunction = fittype('exp(a*x.^2+b*x+c)');
x=[0,0.5,1,1.5,2,2.5];
y=[1,0.8,0.6,0.4,0.2,0];
coff = fit(x', y', fitFunction);
a = coff.a;
b = coff.b;
c = coff.c;
Z=exp(-0.3365*x.^2-0.1660*x+-0.0150);
F=exp(a*x.^2+b*x+c);
G(x)= Z/F;
Walter Roberson
on 30 Apr 2018
Z = @(x) exp(-0.3365*x.^2-0.1660*x+-0.0150);
F = @(x) exp(a*x.^2+b*x+c);
G = @(x) Z(x)./F(x);
fplot(G, [x(1), x(end)])
Ameer Hamza
on 30 Apr 2018
Edited: Ameer Hamza
on 30 Apr 2018
F = exp(-0.3365*x.^2-0.1660*x+(-0.0150))
is actually the result of curve fitting. I think OP is trying to take the inverse of F but forgot to include @(x) sign.
@j.D please use this line exactly as given below,
F = @(x) exp(a*x.^2 + b*x + c);
G = @(x) 1./F(x);
Walter Roberson
on 30 Apr 2018
Ameer Hamza: if you look at the sample calibration function, it is pretty linear. We might suspect that something that is pretty close to 1:1 is expected.
For example it could be the situation that the model was defined at being exactly exp(-0.3365*x.^2-0.1660*x+-0.0150), but that actual data is then obtained, and a correction function needs to be calculated based upon the data.
j.D
on 30 Apr 2018
Thanks guys for your help, both the approaches are good but ameer hamza anwser suits my scenario, thanks again walter and ameer hamza
j.D
on 30 Apr 2018
Walter you might be right but in your case I am not getting the inverse of data can i some how get invert of it with your logic ?
Ameer Hamza
on 30 Apr 2018
@j.D, Walter equation does not invert the data. He was mentioning that you might want to compare the estimated model with an actual model which you already know. If all you want is value of f and g, then the equation i wrote will be sufficient for you.
Ameer Hamza
on 30 Apr 2018
@j.D's comment from answer moved here
Thanks ameer..can you tell me does your code not give me the estimated calibration function ?and thanks for sharing your knowledge with me
Walter Roberson
on 30 Apr 2018
Z = @(x) exp(-0.3365*x.^2-0.1660*x+-0.0150);
F = @(x) exp(a*x.^2+b*x+c);
recipF = @(x) 1./F(x);
G = @(x) Z(x) .* recipF(x);
fplot(G, [x(1), x(end)])
This is based upon your earlier definition
G(x)= Z/F;
but breaks out the 1/F step that you had asked for originally.
We cannot tell whether your estimated calibration function for your purposes is the 1/F or is the Z/F .
Walter Roberson
on 1 May 2018
Flimg = double(YourMatrix) ;
Out = cast(Flimg.*G(Flimg), class(YourMatrix)) ;
More Answers (0)
See Also
Categories
Find more on Interpolation 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!An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
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)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)