Clear Filters
Clear Filters

usage of ode45

13 views (last 30 days)
Hicham on 12 Apr 2024
Commented: Star Strider on 14 Apr 2024
i have 3 differential eqns that i would like to solve using ode45. M, l1, V are all varying w.r.t. time evrything else are just constants

Answers (1)

Star Strider
Star Strider on 12 Apr 2024
imshow(imread('WhatsApp Image...16.45 PM.jpeg'))
syms M(t) I_1(t) I_2 V(t) t g mu A Y T
Eq1 = diff(M) == -g*V*A
Eq1(t) = 
Eq2 = diff(V) == I_1*g/(I_1+I_2) - 8*pi*mu*V/(g*A)
Eq2(t) = 
Eq3 = diff(I_1) == -V
Eq3(t) = 
[VF,Subs] = odeToVectorField(Eq1, Eq2, Eq3)
VF = 
Subs = 
fcn = matlabFunction(VF, 'Vars',{T,Y,g,I_2,mu,A})
fcn = function_handle with value:
g = rand
g = 0.3866
I2 = rand
I2 = 0.7057
mu = rand
mu = 0.0208
A = rand
A = 0.1406
[t,y] = ode45(@(t,y)fcn(t,y,g,I2,mu,A), [0,100], rand(3,1));
plot(t, y)
legend(string(Subs), 'Location','best')
Make appropriate corrections to the symbolic variables (I am not certain that I transcribed them correctly), supply values for the constants parameters, and then use ode45 (or ode15s if the parameters vary significantly in magnitude) to solve it numerically.
Hicham on 13 Apr 2024
what was the function matlabFunction that u used. and how can i program it without the usage of the first ode dm/dt
Star Strider
Star Strider on 14 Apr 2024
The matlabFunction function is part of the Symbolic Math Toolbox.
If you do not want to include the first differential equation, do not include it in the odeToVectorField arguments, using:
[VF,Subs] = odeToVectorField(Eq2, Eq3)

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!