# How to adapt a function to a change of two points?

조회 수: 3(최근 30일)
Daniel Powell 2021년 9월 7일
댓글: Mathieu NOE 2021년 9월 8일
Say you have a function defined in Excel, and you fit the data to a polynomial curve using cftool. Now you want to change just two points of the function, from (x,y)_original to (x,y)_new. You want the rest of the function to adapt to that change. How do you do this?
Something like this: Right now I have a rational fit with 9 coefficients (5th power numerator and 5th power denominator, 5 coefficients in the numerator and 4 coefficients in the denominator while the coefficient of x^5 in the denominator is 1). I can, however, choose a different fit (polynomial, sum of sines etc.) if it would help here.
I have tried changing two coefficients at random to force the function to fit the two new points, but it produces something that doesn't make sense.
Here's what I have: This is a rational fit to a set of Excel data produced with Matlab cftool:
```
p1 = 0.09503;
p2 = 0.8033;
p3 = 2.654;
p4 = 4.375;
p5 = 3.691;
p6 = 1.221;
q1 = 6.399;
q2 = 21.65;
q3 = 34.98;
q4 = 29.02;
q5 = 9.704;
m = (x - 0.9857)./0.1235;
y = (p1*m.^5 + p2*m.^4 + p3*m.^3 + p4*m.^2 + p5*m + p6) ./ (m.^5 + q1*m.^4 + q2*m.^3 + q3*m.^2 + q4*m + q5);
```
I need to make the function go through points (0.78; 0.002) and (1.05473536553; 9.869964329717e-2), while keeping the shape.

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

### 채택된 답변

Mathieu NOE 2021년 9월 8일
hello Daniel
this is my suggestion - a simple anamorphosis of the curve along the vertical axis (= a vertical shift and a multiplicative correction)
plot : code
x = 0.6:0.01:1.2;
p1 = 0.09503;
p2 = 0.8033;
p3 = 2.654;
p4 = 4.375;
p5 = 3.691;
p6 = 1.221;
q1 = 6.399;
q2 = 21.65;
q3 = 34.98;
q4 = 29.02;
q5 = 9.704;
m = (x - 0.9857)./0.1235;
y = (p1*m.^5 + p2*m.^4 + p3*m.^3 + p4*m.^2 + p5*m + p6) ./ (m.^5 + q1*m.^4 + q2*m.^3 + q3*m.^2 + q4*m + q5);
% I need to make the function go through points A = (0.78; 0.002)
% and B = (1.05473536553; 9.869964329717e-2), while keeping the shape.
% what are the y coordinates for x = 0.78 and x = 1.05473536553 ?
x1 = 0.78;
m = (x1 - 0.9857)./0.1235;
y1 = (p1*m.^5 + p2*m.^4 + p3*m.^3 + p4*m.^2 + p5*m + p6) ./ (m.^5 + q1*m.^4 + q2*m.^3 + q3*m.^2 + q4*m + q5); % current coordinate
y1b = 0.002; % new target coordinate
x2 = 1.05473536553;
m = (x2 - 0.9857)./0.1235;
y2 = (p1*m.^5 + p2*m.^4 + p3*m.^3 + p4*m.^2 + p5*m + p6) ./ (m.^5 + q1*m.^4 + q2*m.^3 + q3*m.^2 + q4*m + q5); % current coordinate
y2b = 9.869964329717e-2; % new target coordinate
% solution : search a, b coeff so that :
% y1b = a * y1 + b
% y2b = a * y2 + b
a = (y1b - y2b) / (y1 - y2);
b = y1b - a * y1;
% plot new line
ynew = a * y + b;
plot(x,y,'b',x1,y1b,'*r',x2,y2b,'*k',x,ynew,'g.-');
legend(' original line','new point A','new point B',' new line');
##### 댓글 수: 5표시숨기기 이전 댓글 수: 4
Mathieu NOE 2021년 9월 8일
My pleasure !
Would you mind accepting my answer ?
tx

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

### Community Treasure Hunt

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

Start Hunting!