필터 지우기
필터 지우기

How to find constants when 2 equations are equal?

조회 수: 1 (최근 30일)
Amin Moosavi
Amin Moosavi 2016년 5월 31일
댓글: Star Strider 2016년 6월 1일
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...

채택된 답변

Star Strider
Star Strider 2016년 5월 31일
편집: Star Strider 2016년 5월 31일
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
Amin Moosavi
Amin Moosavi 2016년 6월 1일
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 2016년 6월 1일
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.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Walter Roberson
Walter Roberson 2016년 5월 31일
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.

카테고리

Help CenterFile Exchange에서 Descriptive Statistics에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by