How to plot polynomial in matlab

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

Dyuman Joshi
Dyuman Joshi 2024년 2월 29일
This seems like a homework assignment. Show us what you have tried yet.
Sam Chak
Sam Chak 2024년 2월 29일
First things first, make sure to bookmark the Help Center, and then search for the keyword 'plot'. You will find the relevant information ans examples at this URL: https://www.mathworks.com/help/matlab/ref/plot.html.
It's always a good idea to start by searching in the Help Center before seeking technical assistance, unless the problem is highly specific and no relevant examples can be found in the documentation.
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;
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일

0 개 추천

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.

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

카테고리

도움말 센터File Exchange에서 Stress and Strain에 대해 자세히 알아보기

제품

릴리스

R2023b

질문:

2024년 2월 29일

댓글:

2024년 3월 3일

Community Treasure Hunt

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

Start Hunting!

Translated by