How to do a non linear fit in MATLAB?

2 views (last 30 days)
Luis Hevia Esteva
Luis Hevia Esteva on 17 Nov 2020
Commented: Luis Hevia Esteva on 17 Nov 2020
Hello!
I am trying to get a and b constants from Van der Waals equation of state using a linear regression in MATLAB but I am not sure how to do that. I have all the PVT data needed.
%VdW
R=8.314;
P=[0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1];
T=[296.35 300.95 305.65 310.35 315.15 319.95 329.45 339.45];
V=[1.1717 1.1749 1.1785 1.1822 1.1861 1.1898 1.1976 1.2056];
P= (R*T)/(V-b) - a/V^2;
Is there a way to get those coefficients using a non linear fit function?

Answers (1)

John D'Errico
John D'Errico on 17 Nov 2020
Edited: John D'Errico on 17 Nov 2020
Only VERY poorly. Your data is barely sufficient to estimate anything more than a straight line.
R=8.314;
P=[0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1];
T=[296.35 300.95 305.65 310.35 315.15 319.95 329.45 339.45];
V=[1.1717 1.1749 1.1785 1.1822 1.1861 1.1898 1.1976 1.2056];
If we look at your data, P is a constant. T and V are almost perfectly linearly correlated.
plot(T,V,'o')
So there is essentially no information to estimate any nonlinear behavior at all. In order to find the parameter b, for example, b would correspond to a singularity in the curve. Do you see anything singular happening? Do you see any curvature that would convince anyone that this model applies at all?
  1 Comment
Luis Hevia Esteva
Luis Hevia Esteva on 17 Nov 2020
Dear John,
Thank you very much for your answerr. I actually have several data points. Just did not to fill the page with too many numbers.
Here are the values:
V = [1.1717 1.1749 1.1785 1.1822 1.1861 1.1898 1.1976 1.2056 1.2134 1.2211 1.2293 1.2374 1.2455 1.2541 1.2624 1.2711 1.2802 1.2894 1.2985 1.3073 1.3167 1.3263 1.3367 1.3475 1.3589 1.3695 1.1651 1.1681 1.1715 1.1751 1.1787 1.1822 1.1896 1.1971 1.2045 1.2117 1.2193 1.2269 1.2345 1.2424 1.2502 1.2581 1.2666 1.2748 1.283 1.2912 1.2996 1.3083 1.3175 1.3271 1.3371 1.3463 1.1589 1.1618 1.1649 1.1683 1.1718 1.1752 1.1821 1.1892 1.1962 1.2031 1.2101 1.2172 1.2244 1.2318 1.239 1.2464 1.2543 1.2618 1.2694 1.2768 1.2846 1.2926 1.301 1.3095 1.3184 1.3267 1.1475 1.1501 1.1531 1.1561 1.1594 1.1624 1.1688 1.1752 1.1815 1.1878 1.1942 1.2006 1.207 1.2136 1.22 1.2267 1.2337 1.24 1.2467 1.2533 1.2602 1.267 1.2742 1.2816 1.2889 1.296 1.1373 1.1398 1.1425 1.1455 1.1484 1.1512 1.1571 1.163 1.1689 1.1746 1.1805 1.1864 1.1923 1.1983 1.2043 1.2103 1.2165 1.2223 1.2283 1.2342 1.2402 1.2464 1.2528 1.2593 1.2659 1.272 1.1282 1.1305 1.1331 1.136 1.1387 1.1414 1.1469 1.1524 1.1578 1.1632 1.1686 1.1741 1.1795 1.1851 1.1906 1.1961 1.2019 1.2073 1.2127 1.2182 1.2237 1.2293 1.235 1.2409 1.2468 1.2524 1.12 1.1221 1.1246 1.1273 1.1299 1.1324 1.1376 1.1428 1.1479 1.153 1.1581 1.1631 1.1683 1.1735 1.1786 1.1838 1.1892 1.1941 1.1991 1.2043 1.2094 1.2145 1.2197 1.2252 1.2305 1.2356 1.1126 1.1144 1.1168 1.1194 1.1218 1.1242 1.1292 1.134 1.1389 1.1437 1.1486 1.1533 1.1583 1.163 1.1679 1.1727 1.1777 1.1824 1.187 1.1919 1.1967 1.2015 1.2063 1.2114 1.2163 1.221 1.1061 1.1074 1.1096 1.112 1.1143 1.1167 1.1214 1.126 1.1307 1.1353 1.1398 1.1444 1.1489 1.1535 1.1582 1.1627 1.1674 1.1718 1.1761 1.1807 1.1853 1.1898 1.1944 1.1991 1.2037 1.2081 1.1005 1.1012 1.1029 1.1051 1.1074 1.1097 1.1141 1.1186 1.1231 1.1275 1.1318 1.1361 1.1406 1.1448 1.1492 1.1536 1.158 1.1622 1.1662 1.1705 1.175 1.1792 1.1835 1.1879 1.1923 1.1965 1.0955 1.0957 1.0968 1.0987 1.1009 1.103 1.1074 1.1116 1.1159 1.1201 1.1243 1.1283 1.1326 1.1367 1.1409 1.1451 1.1492 1.1532 1.1571 1.1612 1.1654 1.1693 1.1735 1.1777 1.1817 1.1858 1.0908 1.0907 1.0912 1.0926 1.0947 1.0967 1.1009 1.1049 1.1091 1.1131 1.1171 1.121 1.1251 1.129 1.1331 1.137 1.1409 1.1447 1.1485 1.1524 1.1564 1.1601 1.1641 1.1681 1.172 1.1756];
T = [296.35 300.95 305.65 310.35 315.15 319.95 329.45 339.45 349.05 358.95 368.85 378.75 388.65 398.85 408.75 418.45 428.85 438.85 449.35 459.35 469.85 480.25 490.55 500.55 511.35 521.35 296.35 300.95 305.65 310.35 315.15 319.95 329.45 339.45 349.05 358.95 368.85 378.75 388.65 398.85 408.75 418.45 428.85 438.85 449.35 459.35 469.85 480.25 490.55 500.55 511.35 521.35 296.35 300.95 305.65 310.35 315.15 319.95 329.45 339.45 349.05 358.95 368.85 378.75 388.65 398.85 408.75 418.45 428.85 438.85 449.35 459.35 469.85 480.25 490.55 500.55 511.35 521.35 296.35 300.95 305.65 310.35 315.15 319.95 329.45 339.45 349.05 358.95 368.85 378.75 388.65 398.85 408.75 418.45 428.85 438.85 449.35 459.35 469.85 480.25 490.55 500.55 511.35 521.35 296.35 300.95 305.65 310.35 315.15 319.95 329.45 339.45 349.05 358.95 368.85 378.75 388.65 398.85 408.75 418.45 428.85 438.85 449.35 459.35 469.85 480.25 490.55 500.55 511.35 521.35 296.35 300.95 305.65 310.35 315.15 319.95 329.45 339.45 349.05 358.95 368.85 378.75 388.65 398.85 408.75 418.45 428.85 438.85 449.35 459.35 469.85 480.25 490.55 500.55 511.35 521.35 296.35 300.95 305.65 310.35 315.15 319.95 329.45 339.45 349.05 358.95 368.85 378.75 388.65 398.85 408.75 418.45 428.85 438.85 449.35 459.35 469.85 480.25 490.55 500.55 511.35 521.35 296.35 300.95 305.65 310.35 315.15 319.95 329.45 339.45 349.05 358.95 368.85 378.75 388.65 398.85 408.75 418.45 428.85 438.85 449.35 459.35 469.85 480.25 490.55 500.55 511.35 521.35 296.35 300.95 305.65 310.35 315.15 319.95 329.45 339.45 349.05 358.95 368.85 378.75 388.65 398.85 408.75 418.45 428.85 438.85 449.35 459.35 469.85 480.25 490.55 500.55 511.35 521.35 296.35 300.95 305.65 310.35 315.15 319.95 329.45 339.45 349.05 358.95 368.85 378.75 388.65 398.85 408.75 418.45 428.85 438.85 449.35 459.35 469.85 480.25 490.55 500.55 511.35 521.35 296.35 300.95 305.65 310.35 315.15 319.95 329.45 339.45 349.05 358.95 368.85 378.75 388.65 398.85 408.75 418.45 428.85 438.85 449.35 459.35 469.85 480.25 490.55 500.55 511.35 521.35 296.35 300.95 305.65 310.35 315.15 319.95 329.45 339.45 349.05 358.95 368.85 378.75 388.65 398.85 408.75 418.45 428.85 438.85 449.35 459.35 469.85 480.25 490.55 500.55 511.35 521.35];
P=[0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 120 120 120 120 120 120 120 120 120 120 120 120 120 120 120 120 120 120 120 120 120 120 120 120 120 120 140 140 140 140 140 140 140 140 140 140 140 140 140 140 140 140 140 140 140 140 140 140 140 140 140 140 160 160 160 160 160 160 160 160 160 160 160 160 160 160 160 160 160 160 160 160 160 160 160 160 160 160 180 180 180 180 180 180 180 180 180 180 180 180 180 180 180 180 180 180 180 180 180 180 180 180 180 180 180 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200];
I am trying to use lsqcurvefit to get the a & b parameters but still no luck.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!