Can you help me please?

Use the following set of pressure-volume data to develop a script m-file to find a0 and a1in the following exponential model.
y= ao + a1x +a2x^2
After the model development;
Calculate the root of developed model equation using Newton-Raphson method (xinitial=0). Then,
the code should automatically calculate the predicted volume @ 1.05 bar pressure using the regression model. Also, in the same script m-file this value must be calculated using Lagrange Interpolation and the absolute difference between two finding must be displayed as well.
Data: pressure(bar) volume(m^3)
0.644 32
0.985 25
1.108 22.2
1.363 18
1.631 15
1.934 12
2.356 9
3.1 7.2
The script m-file should work and all inputs must be defined in the beginning of the code.
The results should be presented with fprintfcommand.
The following results should be displayed at the end of the code in this order
a- the model, with a0 and a1 written on it
b- root of the model equation
c- result of the predicted volume at 1.05bar using regression model
d- interpolation result of volume at 1.05bar using lagrange method,
e- the absolute difference between the volume values calculated from model and interpolation.
When script executed above text with correct result should be displayed on command window:
a) The Model: y=(…………)+(…………)*x+(…………)*x^2
b) root value : ……………
c) From model: V=………… when P=1.05bar
d) According to LAGRANGE Method
f interpolated value for P = 1.05 -> V= …………
e) absolute difference between calculated value and interpolation
difference: …………

1 Comment

if i share what i have done, will you help

Sign in to comment.

Answers (1)

Image Analyst
Image Analyst on 21 Jan 2022

0 votes

That's not really an exponential model -- it's a polynomial model. Anyway, attached are some demos that may help you with your fitting.

6 Comments

are you sure that the code is for my question?
Lori: Presumably you have some independent data, like x, and dependent/measured data, like y. And you have a formula you'd like to fit y = a0 + a1 * x + a2 * x^2 where a0, a1, and a2 are coefficients that are to be determined. You can do this with polyfit() so that's why I attached the polyfit() demo.
coefficients = polyfit(x, y, 2) % These are your a values.
a0 = coefficients(3);
a1 = coefficients(2);
a2 = coefficients(1);
Did you try to adapt it to use your data?
yes. can you please write me the right code. it gives error when i try it.
lori, I think you could have done it. In fact I'm sure you've done it by now since it's essentially just a call to polyfit like I showed you already. Anyway, I made it fancy and here's how I did it:
yx = [...]
0.644 32
0.985 25
1.108 22.2
1.363 18
1.631 15
1.934 12
2.356 9
3.1 7.2]
yx = 8×2
0.6440 32.0000 0.9850 25.0000 1.1080 22.2000 1.3630 18.0000 1.6310 15.0000 1.9340 12.0000 2.3560 9.0000 3.1000 7.2000
x = yx(:, 2);
y = yx(:, 1);
plot(x, y, 'b.', 'LineWidth', 2, 'MarkerSize', 30)
grid on;
hold on;
xlabel('Pressure')
ylabel('Volume')
coefficients = polyfit(x, y, 2) % These are your a values.
coefficients = 1×3
0.0037 -0.2315 4.3204
a0 = coefficients(3);
a1 = coefficients(2);
a2 = coefficients(1);
theRoots = roots(coefficients)
theRoots =
31.0588 +13.9518i 31.0588 -13.9518i
% Get predicted value at x = 1.05
xPredicted = 1.05;
yPredicted = polyval(coefficients, xPredicted)
yPredicted = 4.0814
xline(xPredicted, 'Color', 'r', 'LineWidth', 2)
yline(yPredicted, 'Color', 'r', 'LineWidth', 2)
plot(xPredicted, yPredicted, 'r.', 'LineWidth', 2, 'MarkerSize', 50)
ylim([0, 5])
% Now let's plot the whole curve in green to see what it would be for all possible values.
xFit = linspace(0, 35, 1000);
yFit = polyval(coefficients, xFit)
yFit = 1×1000
4.3204 4.3123 4.3042 4.2961 4.2880 4.2800 4.2719 4.2639 4.2558 4.2478 4.2398 4.2317 4.2237 4.2157 4.2078 4.1998 4.1918 4.1838 4.1759 4.1680 4.1600 4.1521 4.1442 4.1363 4.1284 4.1205 4.1126 4.1048 4.0969 4.0890
plot(xFit, yFit, 'g-', 'LineWidth', 2)
Yakup Ardahan BAKIR
Yakup Ardahan BAKIR on 22 Jan 2022
Edited: Yakup Ardahan BAKIR on 22 Jan 2022
so which one of the yFit is the answer for d? @Image Analyst
@Yakup Ardahan BAKIR, where I said
yPredicted = polyval(coefficients, xPredicted)
yPredicted = 4.0814

Sign in to comment.

Products

Asked:

on 21 Jan 2022

Commented:

on 22 Jan 2022

Community Treasure Hunt

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

Start Hunting!