i am trying to find an x value when my y value is equal to 0

8 ビュー (過去 30 日間)
Patrick Deed
Patrick Deed 2020 年 9 月 1 日
コメント済み: Rik 2020 年 9 月 2 日
i am trying to find an x value when my y value is equal to 0
here is what i have so far (this is not giving me the x value but instead displaying
ans =
1×0 empty double row vector
theta=45
h=1.5
g=9.8
v=4
t=0:0.001:1
x=v*cos(theta*3.14/180)*t
y=h+v*sin(theta*3.14/180)*t-0.5*g*t.^2
plot(x,y)
a=find(y<0)
find(y==0,1)

回答 (1 件)

Rik
Rik 2020 年 9 月 1 日
The chance that you end up with a value that is exactly 0 is quite small. You can use code like below as an alternative.
[~,idx]=min(abs(y));
smallest_y=y(idx);
  2 件のコメント
Patrick Deed
Patrick Deed 2020 年 9 月 1 日
thanks a lot Rik,
but it is a task to use the find function to locate this value and another code will not be accepted
Rik
Rik 2020 年 9 月 2 日
Then you must use a tolerance, or adjust your x values so that you actually have a 0. Using a tolerance in this context uses a similar idea to the code above. What do you think you should be using?
Also, you should mention it if you post a homework question.

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

カテゴリ

Help Center および File ExchangeStartup and Shutdown についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by