MATLAB Answers

Inverse hyperbolic fit to data

13 views (last 30 days)
deltaruby
deltaruby on 26 Oct 2020
Edited: Alan Stevens on 27 Oct 2020
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

  0 Comments

Sign in to comment.

Accepted Answer

Mathieu NOE
Mathieu NOE on 26 Oct 2020
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');

  0 Comments

Sign in to comment.

More Answers (1)

Alan Stevens
Alan Stevens on 26 Oct 2020
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 Comment

Alan Stevens
Alan Stevens on 26 Oct 2020
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

Sign in to comment.

Products


Release

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by