ODE45 to solve a complicated problem
2 views (last 30 days)
Show older comments
I'm trying to write a function that can be solved using ODE 45. My function is quite complicated. It is written as h'= T(h) x h. H represents the dipole headings. T represents torque and torque is written as the cross product between dipole headings and the magnetic field. To calculate the magnetic field, the displacement of the magnets is needed. How would I add this into the code?
0 Comments
Answers (1)
Zenin Easa Panthakkalakath
on 17 Aug 2018
Hey Meredith,
Try to define the initial condition (h0), time interval between which you are trying to solve the ODE (tspan) first. For example,
tspan = [0,5]
h0 = 0
Then, call the ode45 function as shown below,
[t,h] = ode45(@odefun, tspan, h0)
Now, we need to define the 'odefun'. Since you require it to be h'= T(h) x h, define it as follows:
function dhdt = odefun(t,h)
dhdt = T(h) * h % You should define T(h) as well
end
Regards, Zenin
0 Comments
See Also
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!