How do I plot a function that has a value given

I'm trying to graph this question from here https://math.stackexchange.com/questions/2638189/express-density-as-a-ratio-of-height
I'm given values for D2 and D1, and then get the ratio D2/D1. I end up with an
equation 4*D2/D1 = 3x^2-x^3, and I need to acquire x from that equation and then plot it.
I tried doing the root of this equation, and when I tried to graph x, D2/D1, it says that "Vectors must be the same length".

回答 (2 件)

Star Strider
Star Strider 2018 年 2 月 7 日
編集済み: Star Strider 2018 年 2 月 7 日

0 投票

Since you did not post your code, I cannot help you troubleshoot it.
Two options —
Symbolic:
syms x
DRatio = 3*x^2-x^3;
xroot = solve(DRatio == 0)
xroot =
0
0
3
Numeric:
xroots = roots([-1 3 0 0])
xroots =
0
0
3

5 件のコメント

jake stan
jake stan 2018 年 2 月 7 日
編集済み: jake stan 2018 年 2 月 7 日
a = [0.4, 0.87, 0.84,0.88] b = [0, 0, 0, 0]
for j = 1:4
r = roots([1 -3 0 4*a(j)]);
b(j) = r(j);
end
plot(a,r);
EDITED: I just noticed that I'm suppose to put the roots into an empty array, and then plot the array A with array B, but I get multiple values for the cube root of my function, I'm not sure which one to put into the empty array
Star Strider
Star Strider 2018 年 2 月 7 日
What is ‘[0.4, 0.87, 0.84,0.88]’?
Walter Roberson
Walter Roberson 2018 年 2 月 7 日
I suspect the a values are 4*D2./D1
jake stan
jake stan 2018 年 2 月 7 日
Oh yeah sorry I just edited
Star Strider
Star Strider 2018 年 2 月 7 日
Try this:
xroots = arrayfun(@(a) roots([1 -3 0 4*a]), [0.4, 0.87, 0.84,0.88], 'Uni',0)
Roots = [xroots{:}]'
Roots =
2.7952 0.8659 -0.6611
2.3916 1.5483 -0.9398
2.4318 1.4934 -0.9252
2.3770 1.5676 -0.9446

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

Walter Roberson
Walter Roberson 2018 年 2 月 7 日

0 投票

For vector D1 and D2, you need D2./D1 instead of D2/D1

カテゴリ

ヘルプ センター および File ExchangeMathematics についてさらに検索

タグ

質問済み:

2018 年 2 月 7 日

編集済み:

2018 年 2 月 7 日

Community Treasure Hunt

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

Start Hunting!

Translated by