Matlab - Change parameters of equation while plot displayed

In summary, the conversation is about using MATLAB to solve differential equations with different parameters and the desire to change these parameters interactively. It is suggested that in order to achieve this, a GUI may need to be programmed or other options such as writing a script or creating a function that takes the parameters as inputs can be explored. It is also mentioned that learning MATLAB from scratch and using optimization tools may be helpful.
  • #1
dkotschessaa
1,060
783
First note that I am just learning Mat lab, and running a program created by someone else.

I have a program which is displaying four differential equations on screen, all with various parameters assigned in the beginning. i.e.

alpha=10;
beta=0.04;
gamma=0.020;

etc.

For equations of the form:
dy(1) = alpha*y(1)*(1-power(y(1)/y(4),1))-beta*y(1)-gamma*y(3)*y(1);

which are being called from a separate file.

I want to be able to change these parameters interactively somehow to see how it effects the graph. Right now I have to go into the code, change the parameter and run again. Is there a way to do this?

Thanks.

Dave K
 
Physics news on Phys.org
  • #2
Hi Dave,

I expect that in order to achieve interactive parameter adjustment, you'll have to program a GUI. If you're new to MATLAB, doing so might require much more work than just changing parameters and rerunning the program. Nevertheless, it might be worth the time investment for reuse later, and there is plenty of documentation available to help. For example, here is an introductory topic on GUI building: http://www.mathworks.com/help/matlab/creating_guis/about-the-simple-guide-gui-example.html

There are other options though. You could simply write a script where you vary the parameters within a loop and overlay the different plots, or you could write your own function that takes the parameters as inputs and uses nested functions to define the equations. Then you could call that function from the command line to solve the equations with whatever parameter values you want.

Hope this helps.
Josh
 
Last edited:
  • #3
kreil said:
Hi Dave,

I expect that in order to achieve interactive parameter adjustment, you'll have to program a GUI. If you're new to MATLAB, doing so might require much more work than just changing parameters and rerunning the program. Nevertheless, it might be worth the time investment for reuse later, and there is plenty of documentation available to help. For example, here is an introductory topic on GUI building: http://www.mathworks.com/help/matlab/creating_guis/about-the-simple-guide-gui-example.html

There are other options though. You could simply write a script where you vary the parameters within a loop and overlay the different plots, or you could write your own function that takes the parameters as inputs and uses nested functions to define the equations. Then you could call that function from the command line to solve the equations with whatever parameter values you want.

Hope this helps.
Josh

Thanks for your reply. I realize that I really need to learn Matlab from scratch, and that much of the point of MATLAB is to try to fit models to experimental data. So my question doesn't even really make sense, now that I know this. I'm used to doing mathy math (in maple) rather than sciency math (in matlab).

As you said, I have to invest more time learning how to do it than doing it, but it'll be worth it. I think we're going to use a genetic algorithm. Don't know how to do that yet, but I see videos and such available.

Thanks,

Dave K
 
  • #4
For anyone's future reference, this is apparently about my newbie misunderstanding of what Matlab does. What I think I need are the optimization tools. Currently going through this webinar:

Global Optimization with MATLAB Products:
http://www.mathworks.com/videos/global-optimization-with-matlab-products-81716.htmll
 
Last edited by a moderator:
  • #5


Yes, there is a way to change the parameters interactively while the plot is being displayed. One way to do this is by using sliders. You can create sliders for each parameter and assign a range of values for them. Then, you can use the "addlistener" function to listen for changes in the sliders and update the parameters accordingly. This way, you can see the effect of changing the parameters on the plot in real-time. Another option is to use the "input" function to prompt the user to input new values for the parameters while the plot is being displayed. This would require adding a loop in your code to continuously prompt for new values and update the plot. Both of these methods will allow you to interactively change the parameters and observe their effect on the plot without having to go into the code and make changes. I recommend exploring these options and consulting the MATLAB documentation for more details on how to implement them. Good luck with your learning!
 

Related to Matlab - Change parameters of equation while plot displayed

What is Matlab?

Matlab is a programming language and interactive environment commonly used in scientific and engineering fields for data analysis, visualization, and algorithm development.

How can I change the parameters of an equation in Matlab?

To change the parameters of an equation in Matlab, you first need to define the equation as a function. Then, you can use the function inputs to change the parameters and see the updated plot. For example, if you have a function called "myEquation" with parameters a and b, you can change the values by calling the function with different inputs, such as myEquation(2,3) to change the values of a and b to 2 and 3 respectively.

Can I change the parameters of an equation while the plot is displayed?

Yes, you can change the parameters of an equation while the plot is displayed in Matlab. This is one of the main advantages of using Matlab for data analysis and visualization. By changing the parameters, you can quickly see the effects on the plot and easily compare different scenarios.

Is it possible to save the changes made to the parameters in Matlab?

Yes, it is possible to save the changes made to the parameters in Matlab. You can save the updated function as a new file or save the workspace, which includes all the variables and functions currently in use. This allows you to easily access and use the updated parameters in future sessions.

Are there any other ways to change the parameters of an equation in Matlab?

Yes, there are other ways to change the parameters of an equation in Matlab. For example, you can use the "set" function to change the properties of a specific plot, such as line color or marker type. You can also use the "subplot" function to display multiple plots with different parameters side by side for comparison. Additionally, you can use the "hold on" command to add new plots to an existing figure and see the effects of changing parameters in real-time.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
9
Views
4K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
763
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
Back
Top