0
$\begingroup$

I have a simple task of plotting the solution to a differential equation under different conditions and can't figure it out.

The solution is

x(t)=Exp(-bt)[cos(wt)+(b/w)*sin(wt)] 

and I need to plot it for 0

f[t_, b_] := [(e^(-b*t))[Cos[t] + b*Sin[t]], 
 t, {t, 0, 20}]

and I think something is wrong in my syntax. I will appreciate any guidance!

$\endgroup$
  • $\begingroup$ You have to use brackets instead of parentheses for arguments. Moreover, you might want Sin and Cos instead of sin and cos. Mathematica is case sensitive. $\endgroup$ – Henrik Schumacher Oct 22 '17 at 0:13
2
$\begingroup$

Maybe you are looking for something like this:

x[t_, b_, w_] := Exp[-b t] (Cos[w t] + b t Sinc[w t])
Manipulate[
 Plot[x[t, b, w], {t, 0, 20}, PlotRange -> {-2, 2}],
 {{b, .1}, -2, 2},
 {{w, 1.}, -2 Pi, 2 Pi}
 ]

If you have specific values for b to plot, you can use, e.g.,

Plot[{f[t,0],f[t,0.1],f[t,1.]}, {t, 0, 20}]
$\endgroup$
  • $\begingroup$ So I did this, f[t_, b_] := Exp[b t] (Cos[t] + b*Sin[t]) which worked great for my function, but them plotting I don't get anything on the plot. I don't want to use the manipulate function because I want to pick specific values for b. $\endgroup$ – K. Schneider Oct 22 '17 at 0:39
  • $\begingroup$ How did you plot then? Note that b needs a specific value if want to use Plot[f[t,b],{t,0,20}]. $\endgroup$ – Henrik Schumacher Oct 22 '17 at 0:40
  • $\begingroup$ Plot[f[t], {t, 0, 20}] $\endgroup$ – K. Schneider Oct 22 '17 at 1:02
  • $\begingroup$ I am trying to figure out how to include b; I need it at specific values of 0, 0.1, and 1. $\endgroup$ – K. Schneider Oct 22 '17 at 1:04
0
$\begingroup$

If you just want plots for b from 0 to 1, you can do this

f[t_, b_] := Exp[-b t] (Cos[t] + b*Sin[t])

Table[Plot[f[t, b], {t, 0, 20}, PlotRange -> All, 
PlotLabel -> "b=" + b], {b, 0, 1, .1}]

but as above, Manipulate works too if you just want to vary b.

Manipulate[Plot[f[t, b], {t, 0, 20}, PlotRange -> {-1, 1}, 
  PlotLabel -> "b=" + b], {b, 0, 1, .1}]
$\endgroup$

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.