0
$\begingroup$

I am trying implement mathematica commands: Table and FindRoot, of a 2 variable function cos(x + 3t) to find all the x values where the cosine function meets the x axis, i.e. cos(x + 3t) == 0, and the times, t, when this happens. Can someone indicate how this can be accomplished, or if it is possible within mathematica?

xInit = 0;
xmin = -4 Pi;
xmax = 4 Pi;
dx = 0.1;

tmin = 0;
tmax = 10;

Astep[x_, t_] := Cos[x + 3 t]

Union[Table[x /. FindRoot[Astep[x, t] == 0, {x, xInit, xmin, xmax}, {t, 0, tmin, tmax}], {xInit, xmin + dx, xmax - dx, dx}], SameTest -> Equal]

The error messages are:

FindRoot::nveq: The number of equations does not match the number of variables in FindRoot[Astep[x,t]==0,{x,xInit,xmin,xmax},{t,0,tmin,tmax}].

ReplaceAll::reps: {FindRoot[Astep[x,t]==0,{x,xInit,xmin,xmax},{t,0,tmin,tmax}]} is neither a list of replacement rules nor a valid dispatch table, and so cannot be used for replacing.

General::stop: Further output of FindRoot::nveq will be suppressed during this calculation.
$\endgroup$
1
$\begingroup$

Try

Table[{t, x /. NSolve[{Astep[x, t] == 0, -4 Pi < x < 4 Pi}, x]}, {t,1, 10}]
(* {{1, {-10.854, -7.71239, -4.5708, -1.4292, 1.71239, 4.85398, 7.99557,11.1372}}
, {2, {-10.7124, -7.5708, -4.4292, -1.28761, 1.85398,4.99557, 8.13717, 11.2788}},...}*)
$\endgroup$
  • $\begingroup$ Thank you Ulrich Neumann, that solved it! $\endgroup$ – Brendan Darrer Jun 20 at 19:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.