Write an executable script file (m-file) that takes no inputs and returns the displacement and stored energy of a spring system after prompting the user for the 1) input forces (in N) on the spring and 2) the spring constant (in N/m).

5 ビュー (過去 30 日間)
The force required to compress a linear spring is given by the equation: F = kx where F is the force in newtons and k is the spring constant in newtons per meter. The potential energy stored in the compressed spring is given by the equation: E = kx^2/2 where E is the energy in joules.
Write an executable script file (m-file) that takes no inputs and returns the displacement and stored energy of a spring system after prompting the user for the 1) input forces (in N) on the spring and 2) the spring constant (in N/m). Use plenty of comments to annotate your code.
I have no idea how to begin to solve this problem. How do I use an input prompt with a script that takes no inputs??
  1 件のコメント
Walter Roberson
Walter Roberson 2020 年 2 月 13 日
How would you use an input prompt in a function that accepted parameters? Is there a difference?
Have you searched the MATLAB documention for the topic of input prompt ?

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

採用された回答

James Tursa
James Tursa 2020 年 2 月 13 日
To get you started, simply create an m-file with something like this at the front end:
F = input('Input the force on the spring (N): ');
k = input('Input the spring constant (N/m): ');
Then add your code to determine x and subsequently calculate E.
  1 件のコメント
JohnLanger
JohnLanger 2020 年 2 月 13 日
I've managed to talk with some people in person, and I think I have a greater comprehension now.

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

その他の回答 (0 件)

カテゴリ

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