Help with MATLAB GUI to Model Simple Harmonic Motion

  • MATLAB
  • Thread starter adelanteh
  • Start date
  • Tags
    Gui Matlab
In summary, the conversation discusses the creation of a GUI app to model simple harmonic motion of a spring with a mass attached to it, including the user's ability to change parameters and see a live visual of the spring's movement and a graph of the motion. The user has already completed the GUI, but needs help with creating a function and using callbacks to update the plot and solve the differential equation with the new parameters.
  • #1
adelanteh
2
0
ranger said:
[Matlab virgin here]

I am in great need of some help. My task is to create GUI app to model simple harmonic motion of a spring with a mass attached to it. The requirements are to have the user be able to change every parameter of the equation:
my'' + cy' + ky' = f(t)

The m, c, k, and f are the usual constants - mass, spring constant and so on. Upon changing these parameters the user should be able to see a live visual of the spring moving and a graph for an analytical understanding of the motion through some specified time of action. By default the time of action should be about 10sec then the simulation stops and the parameters could be changed.

This is what I've done so far:
Made the complete GUI app. This includes all necessary user interfacing, the "live" graph, and spring animation.

Now what I need some help on is the relate all the user inputs to the formula to get the simulation.
Yea, I know I haven't done much because the GUI was the easy part, but I did get the "grid on" and "grid off" buttons to work:biggrin: Other than that, I pretty much didnt do any Callbacks and so on to help analyze the data.

Can someone help me get started?

http://linuxfreak87.googlepages.com/HarmonicSpring.m <-- m-file
http://linuxfreak87.googlepages.com/HarmonicSpring.fig <--fig file

Using Matlab 2009
I don't have so much time.
it's beter to mail me on s.hosseini1365@gmail.com
thanks to all.
 
Physics news on Phys.org
  • #2
[/quote]It's really hard to help you without seeing the code, but I can give you a few tips. First, you need to create a function that takes in the parameters (m, c, k, f) and returns the solution to the differential equation. This could be done using one of Matlab's ODE solvers such as ode45. Once you have the function that returns the solution, you need to set up the GUI so that when the user changes a parameter it updates the plot. To do this you need to use callbacks. A callback is a function that is executed when an event occurs (in this case when a parameter is changed). This can be done by setting the 'Callback' property for each of the UI elements (e.g. sliders, text boxes, etc.) to the name of a function. This function should take the input from the UI element, update the plot accordingly, and then call the ODE solver with the new parameters. Hopefully this helps get you started. Good luck!
 

1. What is MATLAB GUI and how does it help with modeling simple harmonic motion?

MATLAB GUI stands for Graphical User Interface and it is a user-friendly tool that allows scientists to create interactive programs and simulations. It can help with modeling simple harmonic motion by providing a visual representation of the system and allowing for easy manipulation of variables.

2. What are the steps to create a MATLAB GUI for modeling simple harmonic motion?

The steps to create a MATLAB GUI for modeling simple harmonic motion are:1. Define the equations and variables for the system2. Design the GUI layout using MATLAB's GUI design tools3. Write the code to implement the equations and update the GUI4. Test and debug the program

3. Can a MATLAB GUI be used to model complex systems or is it limited to simple harmonic motion?

MATLAB GUI can be used to model various types of systems, including complex systems. However, it may require more advanced coding and design skills to accurately represent and manipulate complex systems.

4. Is it necessary to have prior programming knowledge to create a MATLAB GUI for modeling simple harmonic motion?

Having prior programming knowledge can be helpful in creating a MATLAB GUI, but it is not necessary. MATLAB has a user-friendly interface and provides built-in tools for designing and coding the GUI, making it accessible for users with varying levels of programming experience.

5. Can a MATLAB GUI for modeling simple harmonic motion be shared with others?

Yes, a MATLAB GUI can be shared with others by saving the program as a standalone application or by sharing the code with others. This allows for collaboration and sharing of simulations and models with others in the scientific community.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
6
Views
22K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
3
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
3
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
7K
Replies
1
Views
1K
Replies
2
Views
1K
  • Other Physics Topics
Replies
9
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
5K
  • Introductory Physics Homework Help
Replies
4
Views
1K
Back
Top