how to find two values with a single function

Hey Guys,
I am very new to Matlab and with the help of some tutorials I came to know that Matlab can solve functions . With the help of that I was creating a function to solve Newton's laws of motion
I wanted to find the velocity and time at impact of a falling object using the below function
function [v , t] = my_sin (u ,h)
v = sqrt((u^2)+ (2*9.81*h));
t = (v-u)/9.81;
end
In the command box when I type
my_sin(0 , 10)
I just get the velocity v value , but not the time t .. Can anyone help me to solve this
Kindly looking forward for a solution
Regards
Aadithya

 採用された回答

Star Strider
Star Strider 2018 年 10 月 8 日

0 投票

Function calls only return the first output by default. If you waant both, you need to ask for it.
Try this:
[v, t] = my_sin(u ,h)

4 件のコメント

Aadithya Sathyanarayanan
Aadithya Sathyanarayanan 2018 年 10 月 8 日
I already tried this . But I am not getting the time 't' value
Star Strider
Star Strider 2018 年 10 月 8 日
It works for me:
[v, t] = my_sin(0 ,10)
v =
14.0071
t =
1.4278
Aadithya Sathyanarayanan
Aadithya Sathyanarayanan 2018 年 10 月 8 日
Ohh Okay In the command window . I was typing like
my_sin(0,10)
Instead now I typed like you said
[v, t] = my_sin(0 ,10)
And now I am getting the answer.
Thankyou so much for your reply and solution.
Star Strider
Star Strider 2018 年 10 月 8 日
As always, my pleasure.

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeLoops and Conditional Statements についてさらに検索

製品

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by