Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.
Basic Matlab Question with ode45
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 · ·