Question Sheet 9 - Challenge Problem Example Answers

1. a) Solve the 1st order ODE (dy/dx)=a*cos(ax), with y(0)=0.

DSolve[{y'[x]==a*Cos[a*x],y[0]==0},y[x],x]

b) Define a function with the solution of the DE.

f[x_,a_]:=Sin[a*x]

c) Define a function which plots the solution of the DE for a number of different values of a.

g[a_]:=Plot[f[x,a],{x,0,4π}]

d) Test if your function works for a specific value of a.

g[3]

e) Plot a manipulate with a varying from 1 to 5.

Manipulate[g[a],{a,1,5}]

2. a) define a function for sin(ax)*cos(bx).

func[a_,b_,x_,y_]:=Sin[a*x]Cos[b*y]

b) Define a function that plots the above function over the range 0 to 4π for both x and y. What is more appropriate to use ‘:=’ or ‘=’?

We want to specify our values before our code evaluates so we want to use the ‘dots equals’ to delay the evaluation.

h[a_,b_]:=Plot3D[func[a,b,x,y],{x,0,4π},{y,0,4π}]

c) Use manipulate to plot sin(ax)*cos(bx), with a and b varying over the range 0.1 to 2.

Manipulate[h[a,b],{a,0.1,2},{b,0.1,2}]