Using elements of list to solve a differential equation

I have created a list as shown in picture.

the digits inside f are values of a and q respectively. I want to solve the Mathieu equation..x''[t]+(a-2*q*Cos[2*t])*x[t]==0,x[0]==1,x[0]==1 now i want to use each element of the list to solve this equation. I could solve this equation simply by giving value of a and q as shown in the picture , but then I will have to do it a very large times. So I want to do the same by using each element of the list. I think this can be done by looping but I don't know how. Please help.

• Kamal, this is the third question you post, with minimal changes. Here are a few things you will want to do. 1) DO NOT SHOW IMAGES OF CODE. Instead, paste code in plain text, formatted appropriately, so we can copy / paste it into our MMA. 2) Please explain clearly and completely what you are trying to achieve. Explain the problem in words, then your approach, then show the code. – MarcoB Mar 4 at 17:28
• ok, actually I want to solve the Mathieu equation and plot the a and q parameter, but at the first I posted simpler problem to get the logic to solve it. – Kamal Kumar Mar 5 at 5:53

1 Answer

Here is a modified version of your function:

f[{a_, q_}] := (sol = NDSolve[{x''[t] + (a - 2*q*Cos[2*t])*x[t] == 0,
x[0] == 1, x'[0] == 1}, x, {t, 0, 5}];
(x /. First[sol]) /@ Range[0, 5, 0.2])


so that f[{1,1}] gives the solution for a=1, q=1. To do it for all the a's and q's, try something like this:

aqs = Flatten[Outer[List, Range[0, 1, 0.1], Range[0, 1, 0.1]], 1]
f[#] & /@ aqs


The Outer function gives all the Lists that will define the {a,q} pairs, which is named aqs. These are mapped in the second line to values for f to act on.

• Thanks, this way i got a matrix of different values of x, now I want to select x which lie between -1 and 1, I selected by doing Select[list,-1<#<1&], now how can I know that which element of the list corresponds to which {a,q}. – Kamal Kumar Mar 5 at 8:02
• You can see the correspondence between a, q and the output by looking at the matrix aqs. f is applied to the elements of aqs in order. – bill s Mar 5 at 14:20