How structure code for an equation with multiple variables that change with time.

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

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
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.
If the ODE is known, you may use the built-in function ode45() to solve the ODE and obtain the numerical solution in data form. While ode45() does not return the analytical formula for the dsolve() function can, provided the ODE is solvable.
Hello
Thanks for the input, at this stage due to the complexity of the underlying equations I think I will need to calculate the equations iteratively rather than using an purely analytical solution.
I know this will provide an estimation but it will be accurate enough for my purpose.
Thanks

Sign in to comment.

Answers (0)

Products

Release

R2022a

Asked:

on 13 Feb 2025

Commented:

on 13 Feb 2025

Community Treasure Hunt

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

Start Hunting!