how to write matlab code for physics problem?

9 ビュー (過去 30 日間)
Pablo Sanchez
Pablo Sanchez 2020 年 11 月 18 日
コメント済み: Image Analyst 2020 年 11 月 19 日
If something is accelerated to a speed of 255 m/s in 1.99 seconds, then what is the acceleration and what is the distance that it travels. Also I need to be able to solve for d or solve for t(eg. a speed at 290 m/s and traveled 100m what was the time). I know the equation to solve for d would be vf = vi + a*t and to solve for t is f(t)=.5*a*t^2+Vi*t-d.
Vi=0
a = Delta v/t

回答 (2 件)

James Tursa
James Tursa 2020 年 11 月 18 日
You do not explicitly state that acceleration is constant, but I assume that is the case. The equations then are simply
vf = vi + a*t
df = di + vi*t + 0.5*a*t^2
Use these equations to solve for various items based on what is given.
  4 件のコメント
Pablo Sanchez
Pablo Sanchez 2020 年 11 月 18 日
I have the equations, I need help on writing code to solve it
James Tursa
James Tursa 2020 年 11 月 18 日
This is simple algebra. Plug in what you know and solve for the one variable that you don't know. You need help with that part?

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


Image Analyst
Image Analyst 2020 年 11 月 18 日
Just use
a = (Vf - Vi) / 1.99;
and then solve analytically for d in "Vf^2=Vi^2+2*a*d"
d = .........
Then solve for f. I'm guessing that you're supposed to assume the acceleration stops after 1.99 seconds so a=0 for those times. So the "coasting velocity" would be 255 (not 290). You have to take into account that acceleration is zero after the first 1.99 seconds. It's essentially an algebra problem that can be solved analytically, but you can solve it numerically with MATLAB is you want.
  2 件のコメント
Pablo Sanchez
Pablo Sanchez 2020 年 11 月 18 日
編集済み: Pablo Sanchez 2020 年 11 月 18 日
How would I get it so the user can decide whether I want the code to solve for d or t (depedning on what the user chooses)? I know if loops are involved but how would I structure it.
Image Analyst
Image Analyst 2020 年 11 月 19 日
You can use questdlg() to ask them if they want to solve for d or t.

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

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by