Plot a Potential Energy Graph

28 ビュー (過去 30 日間)
Allen Ruff
Allen Ruff 2021 年 9 月 1 日
編集済み: Erik Huuki 2021 年 9 月 2 日
I have the function U(x) = a x^2 - b x^3 for potential energy and want to plot it with all of a and b positive values. how do i plot this function?
  4 件のコメント
Pooja Lalan
Pooja Lalan 2021 年 9 月 1 日
編集済み: Pooja Lalan 2021 年 9 月 1 日
fplot is used to plot a function of one variable. For instance, if U is a function of only x i.e. U(x), a and b must be constants.
a = 1;
b = 1;
U = @(x) a.*x.^2 - b.*x.^3;
fplot(U)
In the live editor, you can use slider controls to vary a and b to get different line graphs.
However, if you want to plot U as a function of a and b, you can fix x and use fsurf instead.
It is not quite clear how "with all of a and b positive values" translates to a graphic in this context. Is it an animation or some kind of a 3-D visual? Can you point to an example of something similar?
DGM
DGM 2021 年 9 月 2 日
"all of a and b positive values"
You do realize that's an infinite domain, right? You're going to have to settle for less than infinite.

サインインしてコメントする。

回答 (1 件)

Erik Huuki
Erik Huuki 2021 年 9 月 2 日
編集済み: Erik Huuki 2021 年 9 月 2 日
First solve for the roots of the equation. As long as a and b are positive there will be an answer
Turns out for this case it will always bounce off the origin and intersect at a positive value so long as a and b are positive
a = randi([1,10]);
b = randi([1,10]);
r = roots([-b,a]);
x = linspace(0,r);
y = a.*x.^2-b.*x.^3;
plot(x,y)

カテゴリ

Help Center および File Exchange2-D and 3-D Plots についてさらに検索

タグ

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by