MATLAB: Matlab not responding after using ode45

matlab not respondingode45

Hello,
i need to solve a differential equation. I made an m-file with the function to integrate:
function dvdt = velocity(t,r)
dvdt = [-398601*r(1)*((r(1)^2+r(2)^2+r(3)^2)^(-1));
-398601*r(2)*((r(1)^2+r(2)^2+r(3)^2)^(-1));
-398601*r(3)*((r(1)^2+r(2)^2+r(3)^2)^(-1))];
Then i type in the Command Window:
[t,y] = ode45(@velocity, [0 10800], [0 8 0])
Here Matlab stops responding: the symbol ">>" disappears in the Command Windows, if i write an expresssion Matlab does not copmute it. If i push on a button like "New Script" nothing happens or it happens after a long wait.
I read somewhere that may be an issue with Java… I don't have it installed on my pc.
Can you help me? Thanks in advance

Best Answer

This has ABSOLUTELY NOTHING to do with Java. It is time for you to do some reading about ODE solvers, and what makes a problem difficult. If this is homework, I assume the issue will be covered in your next class.
dvdt = @(t,r) [-398601*r(1)*((r(1)^2+r(2)^2+r(3)^2)^(-1));...
-398601*r(2)*((r(1)^2+r(2)^2+r(3)^2)^(-1)); ...
-398601*r(3)*((r(1)^2+r(2)^2+r(3)^2)^(-1))];
[t,y] = ode15s(dvdt, [0 0.01], [0 8 0])
[t,y]
ans =
0 0 8 0
5.7444e-06 0 7.7045 0
1.1489e-05 0 7.3972 0
1.7233e-05 0 7.0763 0
2.9108e-05 0 6.365 0
4.0983e-05 0 5.5637 0
4.9477e-05 0 4.9128 0
5.6094e-05 0 4.3387 0
6.1277e-05 0 3.8295 0
6.5319e-05 0 3.3794 0
6.8467e-05 0 2.9822 0
7.0919e-05 0 2.6316 0
7.2828e-05 0 2.3223 0
7.4316e-05 0 2.0493 0
7.5474e-05 0 1.8083 0
7.6375e-05 0 1.5957 0
7.7078e-05 0 1.4081 0
7.7625e-05 0 1.2425 0
7.805e-05 0 1.0964 0
7.8382e-05 0 0.96746 0
7.864e-05 0 0.85369 0
7.8841e-05 0 0.7533 0
7.8998e-05 0 0.66471 0
7.9119e-05 0 0.58654 0
7.9214e-05 0 0.51757 0
7.9288e-05 0 0.4567 0
7.9346e-05 0 0.40299 0
7.9391e-05 0 0.3556 0
7.9425e-05 0 0.31378 0
7.9453e-05 0 0.27688 0
7.9474e-05 0 0.24432 0
7.949e-05 0 0.21559 0
7.9503e-05 0 0.19024 0
7.9513e-05 0 0.16786 0
7.9521e-05 0 0.14812 0
7.9527e-05 0 0.1307 0
7.9532e-05 0 0.11533 0
7.9535e-05 0 0.10177 0
7.9538e-05 0 0.089801 0
7.954e-05 0 0.07924 0
7.9542e-05 0 0.069922 0
7.9543e-05 0 0.061699 0
7.9544e-05 0 0.054443 0
7.9545e-05 0 0.04804 0
7.9546e-05 0 0.042391 0
7.9546e-05 0 0.037406 0
7.9547e-05 0 0.033007 0
7.9547e-05 0 0.029125 0
7.9547e-05 0 0.0257 0
7.9547e-05 0 0.022678 0
7.9548e-05 0 0.020011 0
7.9548e-05 0 0.017657 0
7.9548e-05 0 0.015581 0
7.9548e-05 0 0.013749 0
7.9548e-05 0 0.012132 0
7.9548e-05 0 0.010705 0
7.9548e-05 0 0.0094461 0
7.9548e-05 0 0.0083352 0
7.9548e-05 0 0.007355 0
7.9548e-05 0 0.0064901 0
7.9548e-05 0 0.0057268 0
7.9548e-05 0 0.0050533 0
7.9548e-05 0 0.0044591 0
7.9548e-05 0 0.0039347 0
7.9548e-05 0 0.0034719 0
7.9548e-05 0 0.0030636 0
7.9548e-05 0 0.0027034 0
7.9548e-05 0 0.0023854 0
7.9548e-05 0 0.0021049 0
7.9548e-05 0 0.0018574 0
7.9548e-05 0 0.0016389 0
7.9548e-05 0 0.0014462 0
7.9548e-05 0 0.0012761 0
7.9548e-05 0 0.0011261 0
7.9548e-05 0 0.00099363 0
7.9548e-05 0 0.00087651 0
7.9548e-05 0 0.00076838 0
7.9548e-05 0 0.00066884 0
7.9548e-05 0 0.00057772 0
7.9548e-05 0 0.00049475 0
7.9548e-05 0 0.00041961 0
7.9548e-05 0 0.00035201 0
7.9548e-05 0 0.00029166 0
7.9548e-05 0 0.00023923 0
7.9548e-05 0 0.00019331 0
7.9548e-05 0 0.00015377 0
7.9548e-05 0 0.00012088 0
7.9548e-05 0 9.3855e-05 0
7.9548e-05 0 8.4299e-05 0
7.9548e-05 0 7.3467e-05 0
7.9548e-05 0 6.0664e-05 0
7.9548e-05 0 4.4143e-05 0
7.9548e-05 0 3.6101e-05 0
7.9548e-05 0 2.5162e-05 0
7.9548e-05 0 2.095e-05 0
7.9548e-05 0 1.5575e-05 0
7.9548e-05 0 1.3599e-05 0
7.9548e-05 0 1.1256e-05 0
7.9548e-05 0 8.2359e-06 0
7.9548e-05 0 3.0429e-06 0
7.9548e-05 0 1.4978e-06 0
7.9548e-05 0 1.2837e-06 0
7.9548e-05 0 1.0122e-06 0
7.9548e-05 0 6.2117e-07 0
7.9548e-05 0 -1.3433e-06 0
7.9548e-05 0 -2.4596e-06 0
7.9548e-05 0 -2.7215e-06 0
7.9548e-05 0 -2.6438e-06 0
7.9548e-05 0 -2.4973e-06 0
7.9548e-05 0 -2.2146e-06 0
7.9548e-05 0 -1.8832e-06 0
7.9548e-05 0 -1.4722e-06 0
7.9548e-05 0 -1.2317e-06 0
7.9548e-05 0 -9.2506e-07 0
7.9548e-05 0 -4.3686e-07 0
First, I ran it for a VERY short time. You were trying to go out to 10800? I tried to get it to go for t as far as 0.01, and it ran into problems at t = 0.000079548.
WALK BEFORE YOU RUN!!!!!!!
See that ode15s terminated within a VERY short time, with a message telling us that it was having severe problems. ode23s had similar issues. ode45 just gets stuck.
Some quick comments - see that when you start out at [0 8 0], the first and third component will ALWAYS be identically zero. Look at the derivatives. See why this happens?
Next, what happens when the components all go to zero as they do? Look at your equations carefully...