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

Star Strider
Star Strider 2021년 8월 6일
This sounds suspiciously like homework!
See the relevant function documentation for examples on how to do all of this.
.
Daniel Vonderhaar
Daniel Vonderhaar 2021년 8월 6일
I sware this is not homework. I guess It does sound like homework. Im sorry. Im just trying to get some help.
John D'Errico
John D'Errico 2021년 8월 6일
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?"

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

 채택된 답변

Star Strider
Star Strider 2021년 8월 6일

0 개 추천

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

Daniel Vonderhaar
Daniel Vonderhaar 2021년 8월 6일
Thank you for your help!
Star Strider
Star Strider 2021년 8월 6일
As always, my pleasure!
.

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

추가 답변 (0개)

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by