Plot always appears as a straight line

9 ビュー (過去 30 日間)
Hieu Nguyen
Hieu Nguyen 2017 年 12 月 4 日
コメント済み: Roger Stafford 2017 年 12 月 5 日
v = [0:100];
m = 4.65*10.^-26;
y = ((m*v)/(4.14*10.^-21)).*exp((-m*v.^2)/2*4.14*10.^-21);
plot(v,y)
title('Density fucntion at t1 and t2')
Hi, I don't know how to fix this but my graph appears to be a straight line intead of an exponential curve. Thanks a lot!
  1 件のコメント
Roger Stafford
Roger Stafford 2017 年 12 月 5 日
@Hieu. Here's a demonstration of why you should be careful with how you use parentheses:
x = 60/5*12
y = 60/(5*12)
z = 60/5/12
Notice that in 'y' and 'z' there is division by 12, whereas in 'x' it is multiplied. That is apparently the source of your difficulty with the quantity 4.14*10.^-21. It was multiplied rather than divided because you left out the all-important parentheses.

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

採用された回答

Roger Stafford
Roger Stafford 2017 年 12 月 4 日
Are you sure the second "4.14*10.^-21" doesn't belong in the denominator:
y = ((m*v)/(4.14*10.^-21)).*exp((-m*v.^2)/(2*4.14*10.^-21));
If so, and if you change the range of v to:
v = [0:1000];
you will get a nicely curved plot.
  2 件のコメント
Hieu Nguyen
Hieu Nguyen 2017 年 12 月 4 日
Let's define that quantity as A. I am trying to plot this function: f(x) = ((mx)/A) * exp((-mv^2)/2A). I still get a straight line.
Greg
Greg 2017 年 12 月 4 日
編集済み: Greg 2017 年 12 月 4 日
Did you put the parenthesis around 2.*A?

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

その他の回答 (1 件)

Greg
Greg 2017 年 12 月 4 日
First, I suspect you missed parenthesis is your exp denominator. The magic of using constants. Second, most functions look like straight lines if you stay near the origin. Try plotting further out in v.
v = 0:1000;
m = 4.65*10.^-26;
denom = (4.14*10.^-21);
y = ((m*v)/denom).*exp((-m*v.^2)/(2*denom));
a = axes(figure);
plot(a,v,y);
title('Density function at t1 and t2')
  2 件のコメント
Hieu Nguyen
Hieu Nguyen 2017 年 12 月 4 日
I see. Thanks a lot! One of the reasons I am not fond of matlab sometimes.
Greg
Greg 2017 年 12 月 4 日
編集済み: Greg 2017 年 12 月 4 日
That has nothing to do with MATLAB. That's a mathematical given.
Also, it was unfair to accept my answer. It was identical, and 10 minutes later than, Roger Stafford's answer.
Please unaccept mine and accept his.

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

カテゴリ

Help Center および File ExchangeDescriptive Statistics についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by