Hi, i'm trying to fit the model (P+a)(V+b)=(Po+a)*b to some data in MATLAB (where a and b are constants and Po is the value of P at V=0), I'm just wondering how you do this.
My data is:
P = [5 7.5 10 12.5 15 17.5 20 25 30 35 40 45 50 55 60 65];
V = [32.89 26.48 22.28 19.16 17.25 14.97 13.40 10.66 9.38 7.88 6.66 5.89 4.79 4.49 2.43 1.37];
Thanks

 채택된 답변

Mathieu NOE
Mathieu NOE 2020년 10월 26일

1 개 추천

hi
below the code that solve your problem using fminsearch
P = [5 7.5 10 12.5 15 17.5 20 25 30 35 40 45 50 55 60 65];
V = [32.89 26.48 22.28 19.16 17.25 14.97 13.40 10.66 9.38 7.88 6.66 5.89 4.79 4.49 2.43 1.37];
% fminsearch optimization loop
fun = @(x)norm((P+x(1)).*(V+x(2))-(x(3)+x(1))*x(2)); %a = x(1), b=x(2), Po = x(3)
x0 = [0, 0, 0];
X = fminsearch(fun,x0);
a = X(1)
b=X(2)
Po = X(3)
% check on plot :
Vfit=((Po+a)*b)./(P+a) - b;
figure(1), plot(P,V,'b',P,Vfit,'r');grid
legend('experimental','fit');

추가 답변 (1개)

Alan Stevens
Alan Stevens 2020년 10월 26일

2 개 추천

Here's an alternative, with V as the independent variable and P as the dependent one:
% Data
P = [5 7.5 10 12.5 15 17.5 20 25 30 35 40 45 50 55 60 65]';
V = [32.89 26.48 22.28 19.16 17.25 14.97 13.40 10.66 9.38 7.88 6.66 5.89 4.79 4.49 2.43 1.37]';
% (P + a)(V + b) = (P0 + a)*b
% P*V +a*V + b*P + a*b = P0*b + a*b
% V*a + P*b - P0b = -P*V
% M*X = C where M = [V P -1]; X = [a; b; P0b]; C = -P.*V;
M = [V P -ones(size(V))];
C = -P.*V;
X = M\C;
a = X(1);
b = X(2);
P0 = X(3)/b;
disp('a b P0')
disp([a b P0])
p = (P0 + a)*b./(V + b) - a;
plot(V,P,'o',V,p,'*-'),grid
xlabel('V'),ylabel('P')
legend('data','curve fit')
This produces

댓글 수: 1

Alan Stevens
Alan Stevens 2020년 10월 26일
편집: Alan Stevens 2020년 10월 27일
With V as the independent variable
p = (P0 + a)*b./(V + b) - a;
plot(V,P,'o',V,p,'*-')
should now be replaced by
v = (P0 + a)*b./(P + a) - b;
plot(P,V,'o',P,v,'*-')
with corresponding label changes.
The result should now look like

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

카테고리

도움말 센터File Exchange에서 Get Started with Curve Fitting Toolbox에 대해 자세히 알아보기

제품

릴리스

R2020b

태그

질문:

2020년 10월 26일

편집:

2020년 10월 27일

Community Treasure Hunt

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

Start Hunting!

Translated by