I am using Matlab for a class, and unfortunately, I don't have much experience in it.
For my problem, I need to solve an ordinary differential equation using Matlab's built-in ODE45 function. Using some tutorials, I came up with the following code to solve and plot my function.
[t,x] = ode45(@dfile,[0,20],[0;0]);
xlabel('t'), ylabel('y'), grid
function xprime = dfile(t,x)
xprime = zeros(2,1);
xprime(1) = x(2);
xprime(2) = F*cos(t) - a*x(2) - x(1)^3;[/b]
It works well, but I need to be able to vary F and a using a loop to get multiple plots as the two variables change. Yet I can't for the life of me figure out how to get a variable from the main function JTD into the function xprime when I call the ode45 function.
If I could figure that out, it would help me immensely in continueing my program.
0 · ·