Re: Syntax
- To: mathgroup at smc.vnet.net
- Subject: [mg25566] Re: [mg25528] Syntax
- From: Tomas Garza <tgarza01 at prodigy.net.mx>
- Date: Sat, 7 Oct 2000 03:36:14 -0400 (EDT)
- Sender: owner-wri-mathgroup at wolfram.com
For one thing, the first line (Solve...) seems to be completely
unrelated to the rest.
Second, if you are really giving the definition of a function yc[t], you
must use := (SetDelayed) instead of just = (Set). (By the way, you
have written Cost[t] instead of Cos[t] in line 2). Same goes for yp[t].
Then, if
In[1]:=
yc[t_] := c1 Cos[t] + c2 Sin[t] + c3 t Cos[t] + c4 t Sin[t];
it looks as if
In[2]:=
yc''''[t] + 2 yc''[t] + yc[t]
Out[2]=
2 c1 Cos[t] - 4 c4 Cos[t] + 2 c3 t Cos[t] + 2 c2 Sin[t] + 4 c3 Sin[t] +
2 c4 t Sin[t] +
2 (-c1 Cos[t] + 2 c4 Cos[t] - c3 t Cos[t] - c2 Sin[t] - 2 c3 Sin[t] -
c4 t Sin[t])
gives 0, as a simple visual examination shows. Nothing to Expand.
Now, if
In[3}:=
yp[t_] := a t^2 Cos[t] + b t^2 Sin[t];
then
In[4]:=
formula = Simplify[ yp''''[t] + 2 yp''[t] + 2 Sin[t] - 4 Cos[t]]
Out[4]=
-(4 + a(8 + t^2)) Cos[t] - (-2 + b (8 + t^2)) Sin[t]
which is already nicely expressed in terms of Cos[t] and Sin[t] without
much hassle
No need for Collect[...,{Cos[t], Sin[t]}].
But then, unfortunately,
In[5]:=
formula[[1, 1]]
Out[5]=
-1
In[6]:=
formula[[2, 1]]
Out[6]=
-1
as you can check by yourself by looking at formula under FullForm. So
your eqns don't make any sense and we can't go any further.
I'm afraid your problem is far more than just a matter of syntax.
Tomas Garza
Mexico City
"Adnan" <karpov at softhome.net> wrote:
> I am having problem with folllowing code. Probablly a syntax error.
> Can anyone figure out what's wrong here?
>
>
> Solve[r^4 + 2 r^2 + 1 == 0, r]
> yc[t_] = c1 Cos[t] + c2 Sin[t] + c3 t Cost[t] + c4 t Sin[t];
> Print["yc[t] = ", yc[t]]
> yc''''[t] + 2 yc''[t] + yc[t]
> Expand[yc''''[t] + 2 yc''[t] + yc[t]]
>
> yp[t_] = a t^2 Cos[t] + b t^2 Sin[t];
> Print["yp[t] = ", yp[t]];
> formula = yp''''[t] + 2 yp''[t] + 2 Sin[t] - 4 Cos[t]
> formula = Expand[formula]
> formula = Collect[formula, {Cos[t], Sin[t]}]
> eqns = {formula[[1, 1]] == 0, formula[[2, 1]] == 0};
> TableForm[eqns]
> solset = Solve[eqns, {a, b}]
>
> yp[t_] = ReplaceAll[yp[t], solset[[1]] ];
> Print["yp[t] = ", yp[t] ];
> yp''''[t] + 2 yp''[t] + yp[t] + 2 Sin[t] - 4 Cos[t]
>
> Expand[yp''''[t] + 2 yp''[t] + yp[t] + 2 Sin[t] - 4 Cos[t] ]
>
> y[t_] = yc[t] + yp[t];
> Print["y[t] = ", y[t] ]
>
> eqns = {y[0] == 2, y'[0] == -1, y''[0] == 4, y'''[0]
== 1};
> TableForm[eqns]
> sol = Solve[eqns, {c1, c2, c3, c4}]
>
> y[t_] = ReplaceAll[y[t], sol[[1]]]
> Print["y[t] = ", y[t]]
>
> ExpandAll[
> {y''''[t] + 2 y''[t] + y[t] + 2 Sin[t] - 4 Cos[t] == 0,
> y[0] == 2,
> y'[0] == -1,
> y''[0] == 4,
> y'''[0] == 1}]
>
> Plot[y[t], {t, 0, 3.2},
> PlotRange -> {{0, 3.2}, {0, 5.3}},
> Ticks -> {Range[0, 3, 1], Range[0, 5, 1]}];
>
> Plot[y[t], {t, 0, 10.5},
> PlotRange -> {{0, 10.5}, {-25, 54}},
> Ticks -> {Range[0, 10, 1], Range[-20, 50, 10]}];
>
> Plot[y[t], {t, 0, 30},
> PlotRange -> {{0, 30}, {-500, 500}},
> Ticks -> {Range[0, 30, 10], Range[-500, 500, 100]}];