Effacer les filtres
Effacer les filtres

How to find constants when 2 equations are equal?

1 vue (au cours des 30 derniers jours)
Amin Moosavi
Amin Moosavi le 31 Mai 2016
Commenté : Star Strider le 1 Juin 2016
Hi there! I have a function of (x) (and it's polynomial,degree=5) and I want to make it equal to "c1*exp(c2*x)". How can I find these two constants???? I would appreciate your helps...

Réponse acceptée

Star Strider
Star Strider le 31 Mai 2016
Modifié(e) : Star Strider le 31 Mai 2016
You can fit your polynomial with the core MATLAB funciton fminsearch and an extra line of code:
pf = @(x) x.^4 - 2*x.^3 + 3*x.^2 - 5*x + 4; % Polynomial Function
ef = @(c,x) c(1).*exp(c(2)*x); % Exponential Function
x = linspace(0, 5, 10); % Vector Of ‘x’ Values (Arbitrary)
SSECF = @(c) sum((pf(x) - ef(c,x)).^2); % Sum Squared Error Cost Function
c0 = [1; 1]; % Initial Parameter Estimates
[c, SSE] = fminsearch(SSECF, c0) % Estimate ‘c’, Return Sum-Squared-Error At Convergence
figure(1)
plot(x, pf(x), 'bp')
hold on
plot(x, ef(c,x), '-r')
hold off
grid
Substitute your own polynomial function. The plot is optional.
EDIT You need to include a y-offset term. With that, a single exponential fits very well:
d = load('Amin Moosavi a3.mat');
x = d.locs;
y = d.pks;
ef = @(c,x) c(1).*exp(c(2)*x) + c(3); % Exponential Function
SSECF = @(c) sum((y - ef(c,x)).^2); % Sum Squared Error Cost Function
c0 = [100; -1; 400]; % Initial Parameter Estimates
[c, SSE] = fminsearch(SSECF, c0) % Estimate ‘c’, Return Sum-Squared-Error At Convergence
figure(1)
plot(x, y, 'bp')
hold on
plot(x, ef(c,x), '-r', 'LineWidth',1)
hold off
grid
text(150, 470, sprintf('f(x) = %.1f\\cdote^{%.4f\\cdotx} + %.1f', c))
  11 commentaires
Amin Moosavi
Amin Moosavi le 1 Juin 2016
Dear @Star Strider
I did what you said and it worked. i don't know how should i say thank you. I hope God gives you every good thing you want.
thanks a lot
I hope to see you soon in my country.
Star Strider
Star Strider le 1 Juin 2016
As always, my pleasure!
I wish the same for you.
I doubt I’m going to do any traveling anytime soon, but thank you for the invitation.

Connectez-vous pour commenter.

Plus de réponses (1)

Walter Roberson
Walter Roberson le 31 Mai 2016
You cannot get out any meaningful results if you are working with a single x. In such a case the exact solution is
c2 = ln(a5*x^5+a4*x^4+a3*x^3+a2*x^2+a1*x+a0-c1)/x
so as you change c1, c2 changes as well, and for any given x you can force c2 to become imaginary (by using a large enough c1 that the polynomial minus c1 becomes negative, leading to ln() of a negative number.
For any two given x = x1, x2, you would have
c1 = a5*x2^5+a4*x2^4+a3*x2^3+a2*x2^2+a1*x2-exp(RootOf(exp(Z)-a5*x2^5-a4*x2^4-a3*x2^3-a2*x2^2-a1*x2+a5*x1^5+a4*x1^4+a3*x1^3+a2*x1^2+a1*x1-exp(Z*x1/x2)),Z)+a0
c2 = RootOf(exp(Z)-a5*x2^5-a4*x2^4-a3*x2^3-a2*x2^2-a1*x2+a5*x1^5+a4*x1^4+a3*x1^3+a2*x1^2+a1*x1-exp(Z*x1/x2),Z)/x2
here, RootOf(f(Z),Z) means the set of Z such that f(Z) becomes 0 -- the roots of the expression. You can see that the values you calculate would be very much tied up to the exact values of x1 and x2.
If you were hoping to take a series of values for the polynomial and fit the best c1, c2 for the entire series, then the result is going to depend a lot on which values you fit against.

Catégories

En savoir plus sur Descriptive Statistics dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by