I need some help with Curve Fitting
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Daniel Vonderhaar
el 6 de Ag. de 2021
Comentada: Star Strider
el 6 de Ag. de 2021
Hello!
I have two vectors as shown here
volume = 1:7;
pressure = [3102,2385,1344,886,623,452,411];
I want to have them, fit curves to the data with first-,second-, and third-order polynomails. I want to use polyfit and polyval.
Then I want to plot the three fitted functions on the same graph. I think I want to have a stepsize of 0.2m^3 in order to smooth the curves.
Next I want to plot the actual data from the table on the same graph as the fitted curves, With (im not sure if you can do this) unconnected circles
And then finnally I want to use legend lebels like this 1st order, 2nd order,3rd order and original data.
And would it be possible to treat the volume as the independent (x) variable and treat the pressure as the dependent (y) variable?
Would any of you be able to help me with this?
Please let me know
Thanks
3 comentarios
John D'Errico
el 6 de Ag. de 2021
While it may not have been explicitly homework, it is still surely a student project of some sort, that should arguably have been treated as homework.
And will you please stop titling EVERY question of yours with "I need some help please?"
Respuesta aceptada
Star Strider
el 6 de Ag. de 2021
‘I sware this is not homework. I guess It does sound like homework. Im sorry. Im just trying to get some help.’
O.K. I’ll take you at your word.
volume = 1:7;
pressure = [3102,2385,1344,886,623,452,411];
vv = min(volume):0.2:max(volume);
pv = zeros(3,numel(vv));
for k = 1:3
p{k} = polyfit(volume,pressure,k);
pv(k,:) = polyval(p{k}, vv);
end
figure
hold on
for k = 1:3
plot(vv, pv(k,:), 'DisplayName',sprintf('Polynomial Fit Order %d',k))
end
scatter(volume,pressure,'filled', 'DisplayName','Data')
hold off
grid
legend('Location','best')
xlabel('Volume')
ylabel('Pressure')
Make appropriate changes to get the result you want.
.
2 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Interpolation en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!