How can I transform polynomials such that they overlay each other?

조회 수: 1 (최근 30일)
Harm Gilsing
Harm Gilsing 2022년 5월 13일
편집: Jon 2022년 5월 13일
I created a plot consisting of 5 polynomials of 2nd degree (see attachment). The coefficients of those polynomials are:
  • p = [-3.790466223990772e-04,0.004074643555077,-0.033133211227356]
  • p1 = [2.463875132721238e-04,3.802876924742511e-04,1.953560252697614e-05]
  • p2 = [2.019059367863187e-04,1.156123725241465e-04,2.614767201627642e-04]
  • p3 = [2.621495684977407e-04,8.229496951057387e-05,2.218464586208243e-04]
  • p4 = [4.451376205036274e-04,-1.027157047259503e-04,5.282799436326823e-04]
Does anyone know if it is possible to transform (4 of) the polynomials in order to let them overlay with each other?
Thanks in advance!
  댓글 수: 1
Jon
Jon 2022년 5월 13일
What do you mean by "overlay"? Do you want them to all have the same y value at some particular value of x?

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

답변 (1개)

Jon
Jon 2022년 5월 13일
편집: Jon 2022년 5월 13일
Assuming you want them to match at some particular value of x you could do something like this.
By the way the first curve in your set of polynomials doesn't seem to look like the one you show in your figure. Maybe some transcription error writing down the coefficients?
% define x value at which curves will match
xMatch = 1;
% define matrix of polynomial coefficients, each row is a polynomial curve
P = [-3.790466223990772e-04,0.004074643555077,-0.033133211227356;
2.463875132721238e-04,3.802876924742511e-04,1.953560252697614e-05;
2.019059367863187e-04,1.156123725241465e-04,2.614767201627642e-04;
2.621495684977407e-04,8.229496951057387e-05,2.218464586208243e-04;
4.451376205036274e-04,-1.027157047259503e-04,5.282799436326823e-04];
% get number of curves for future use
numCurves = size(P,1);
% calculate value of first polynomial at the value of x where curves are to
% match
yMatch = polyval(P(1,:),xMatch);
% loop through curves to compute match
Pmatch = zeros(size(P)); % preallocate
for k = 1:numCurves
% compute offset from first curve at the match point
delta = polyval(P(k,:),xMatch) - yMatch;
% compute corrected coefficients, just modify the constant term
Pmatch(k,:) = [P(k,1:end-1),P(k,end)-delta];
end
% check results
xplot = linspace(0,5);
% original curves
figure
for k = 1:numCurves
plot(xplot,polyval(P(k,:),xplot))
hold on
end
title('original curves')
hold off
% original curves
figure
for k = 1:numCurves
plot(xplot,polyval(Pmatch(k,:),xplot))
hold on
end
title('matched curves')
hold off

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by