This works:
function [xdot] = RVorbitPropogation(t, x, mu) r = sqrt((x(1))^2 + (x(2))^2 + (x(3))^2); %Define R xdot = [x(4); x(5); x(6); -(mu/((r)^3))*x(1); -(mu/((r)^3))*x(2); -(mu/((r)^3))*x(3); mu;]; %Define equation end
mu = 42; % Create ‘mu’ tspan = [0 5]; % Create ‘tspan’ y0 = [zeros(6,1); 1]; % Create ‘y0’ [T, Y] = ode45(@(t,x) RVorbitPropogation(t,x,mu),tspan, y0);
figure(1) plot(T,Y) grid
Note that in the ode45 call, ode45 only ‘sees’ the ‘(t,x)’ arguments, allowing the anonymous function call to ‘RVorbitPropogation’ to acquire ‘mu’ from the workspace.