Passing computations from ODE45

  • Thread starter Thread starter adschutte
  • Start date Start date
  • Tags Tags
    Ode45
AI Thread Summary
To pass variables computed within a user-defined function called by ODE45 in MATLAB, such as the variable Fc in the provided example, one effective approach is to use nested functions or handle functions. By defining Fc as a persistent variable or using a global variable, it can be accessed outside the function without needing to recompute it. Alternatively, consider using a structure to store multiple outputs, including Fc, which can then be returned alongside the primary outputs of the ODE function. This method allows for efficient data management and avoids unnecessary calculations. Additionally, embedding the ODE function within a larger script can facilitate variable sharing without the need for external files.
adschutte
Messages
1
Reaction score
0
Does anyone know a trick to pass variables computed in the user defined function called by ODE45 in MATLAB?

For example, imagine you have the following code:

%=======================================
[t,y] = ode45('DiffEQ',dt,Initial,options);

function dy = DiffEQ(t,y)
Fc = y(1)*y(2);
dy(1) = y(2);
dy(2) = -k*y(1)-c*y(2)+Fc;
%=======================================

How can we pass Fc as an output? I don't want to re-compute Fc with the solutions. Thanks for any tips.
 
Computer science news on Phys.org
Save it in a file or embed the code in a bigger one. Is not very consuming to do an ode45.
 
In my discussions elsewhere, I've noticed a lot of disagreement regarding AI. A question that comes up is, "Is AI hype?" Unfortunately, when this question is asked, the one asking, as far as I can tell, may mean one of three things which can lead to lots of confusion. I'll list them out now for clarity. 1. Can AI do everything a human can do and how close are we to that? 2. Are corporations and governments using the promise of AI to gain more power for themselves? 3. Are AI and transhumans...
Thread 'ChatGPT Examples, Good and Bad'
I've been experimenting with ChatGPT. Some results are good, some very very bad. I think examples can help expose the properties of this AI. Maybe you can post some of your favorite examples and tell us what they reveal about the properties of this AI. (I had problems with copy/paste of text and formatting, so I'm posting my examples as screen shots. That is a promising start. :smile: But then I provided values V=1, R1=1, R2=2, R3=3 and asked for the value of I. At first, it said...
Back
Top