How structure code for an equation with multiple variables that change with time.
Show older comments
Hello,
Im relativley new to MATLAB nan coding and unsure how to proceed in structuring my Matlab code.
For instance. if I had an equation (1) that out puts (a) and has mutliple varibles (B), (C), and (D) that all are made up of of an equation that varies with time (t) how should I structure my code. Should I be using Function, while or For loops?
a = b + c + d
and time (t) equals a constant (e) divided by (a)
t = a/e
This may be a bit of a vauge question but any examples of how I might structure this would be awesome. Any suggestions on the format would be great. Any General Solution would be great.
(t) can finish at any time (t_n) or if another variable hits a certain point
I am working through the free MATLAB training so I am able to understand how individual elements of code works but just unsure how to put it all together.
3 Comments
Walter Roberson
on 13 Feb 2025
Edited: Walter Roberson
on 13 Feb 2025
We need more context. The answer is going to be different if you are using Partial Differential Equation Toolbox, compared to if you are using Ordinary Differential Equations, or compared to if you are doing some kind of optimization; and different again if you are using Simscape
Hi @MIchael
Begin by thoroughly understanding the mathematical concepts related to the system. For instance, if you know that some variables vary with time, you can describe these variables
as either a function of time,
, or as the rate of change,
, which represents the speed at which the variable
changes over a specific period. This allows you to integrate
to obtain
. The latter is known as an Ordinary Differential Equation (ODE).
If you need to repeatedly compute the state of a variable using the same function
that varies with time, you must determine whether to use a vectorized-time approach or a looping approach for a specific time interval.
MIchael
on 13 Feb 2025
Answers (0)
Categories
Find more on Ordinary Differential Equations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!