How to plot polynomial in matlab

1 次查看(过去 30 天)
Madison
Madison 2024-2-29
equation is f(x) = 150x - 400x^2 + 500x^3
Want to plot f(x) for x= 0 to 0.8
need to have a legend
  4 个评论
Madison
Madison 2024-3-3
I have tried the following - Getting an error on line 5
epsilon = linspace(0,0.8,100);
sigma = zeros(1,100);
i = 1:length(epsilon);
strain = epsilon(i);
stress = 150*strain - 400*strain^2 + 500*strain^3;
sigma(i) = stress;
figure;
plot (epsilon, sigma)
xlabel('Strain(ε)');
ylabel('Stress(σ)(kPa)');
title('Stress/Strain for Foam');
grid on;
Dyuman Joshi
Dyuman Joshi 2024-3-3
You need to use element-wise power - power, .^
epsilon = linspace(0,0.8,100);
sigma = 150*epsilon - 400*epsilon.^2 + 500*epsilon.^3;
figure;
plot (epsilon, sigma)
xlabel('Strain(ε)');
ylabel('Stress(σ)(kPa)');
title('Stress/Strain for Foam');
grid on;

请先登录,再进行评论。

回答(1 个)

Alexander
Alexander 2024-2-29
编辑:Alexander 2024-2-29
Some homework assistance and solution:
x = linspace(0,0.8,1000);
y = 150*x - 400*x.^2 + 500*x.^3;
plot(x,y)
  1 个评论
Dyuman Joshi
Dyuman Joshi 2024-2-29
编辑:Dyuman Joshi 2024-2-29
I believe that's solving the problem rather than assisting.
I suggest you edit your answer accordingly.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Programming 的更多信息

产品


版本

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by