MathGroup Archive 2008

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Piecewise function involving matrices

  • To: mathgroup at smc.vnet.net
  • Subject: [mg91231] Re: Piecewise function involving matrices
  • From: "Kaveh Khodjasteh" <kavehkh at gmail.com>
  • Date: Sun, 10 Aug 2008 01:53:52 -0400 (EDT)
  • References: <g7k0gn$ieh$1@smc.vnet.net> <489DB263.1010905@gmail.com>

Thanks for your reply. Yes, I know I could use Boole or UnitStep to
achieve it but was wondering if there is a nicer solution that uses
piecewise with some sort of Hold command.

Kaveh

On Sat, Aug 9, 2008 at 11:06 AM, Jean-Marc Gulliet
<jeanmarc.gulliet at gmail.com> wrote:
> kaveh wrote:
>
>> I am trying to define a piecewise matrix function of time with
>> Mathematica that I later want to use to transform another matrix as a
>> function of time and integrate it. To make it simple I have
>>
>> In[163]:= A={{1,.1},{.1,-1}};
>> In[171]:= H0={{0,b},{b,0}};
>> In[172]:= F[t_]:=Piecewise[{{exp[-I t] A,0<t<1},{exp[+I t] A,1<t<2}}]
>
> Syntax error: Except if you have already defined the function exp somewhere
> else, exp should be written Exp, which is the standard exponential function
> in Mathematica.
>
>> In[173]:= F[0.1]
>> Out[173]= {{exp[-0.1 \[ImaginaryI]],0.1 exp[-0.1 \[ImaginaryI]]},{0.1
>> exp[-0.1 \[ImaginaryI]],-exp[-0.1 \[ImaginaryI]]}}
>>
>> In[181]:= H[t_]:= Inverse[F[t]].H0.F[t]+H0.H0
>>
>> In[182]:= H[0.4]
>> Out[182]= {{0.19802 b+b^2,-0.980198 b},{-0.980198 b,-0.19802 b+b^2}}
>>
>> The problem is that when I evaluate H[t] for a given number, it
>> returns the right value but if t is a symbol Mathematica naturally
>> leaves it as unevaluated. This by itself is nice, however when I want
>> to integrate H[t], I run into problems.
>> Say
>> In[183]:= Integrate[H[x],{x,0,1}]
>
> <snip>
>
>> Notice that the output is not a 2x2 matrix but has dimensions
>> {2,2,2,2}!
>> Same with:
>> In[186]:= Integrate[H[x][[1,1]],{x,0,1}]
>> Out[186]= {{0.00990099 (20. b+101. b^2),0.00990099 (-99. b+101. b^2)},
>> {0.00990099 (-99. b+101. b^2),0.00990099 (-20. b+101. b^2)}}
>> which should be just a number but is a 2x2 matrix!
>>
>> Obviously there is something wrong with the treatment of piecewise as
>> an array instead of a flat thing.
>
> Since Mathematica 6.0, Integrate works well with *continuous* piecewise
> functions.
>
> In your case, you should use *Boole* to write the piecewise function. For
> instance,
>
> In[1]:= A = {{1, .1}, {.1, -1}};
>
> H0 = {{0, b}, {b, 0}};
>
> F[t_] := Boole[0 < t < 1] Exp[-I t] A + Boole[1 < t < 2] Exp[+I t] A
>
> F[0.1]
>
> H[t_] := Inverse[F[t]].H0.F[t] + H0.H0
>
> H[0.4]
>
> Out[4]= {{0.995004- 0.0998334 I,
>  0.0995004- 0.00998334 I}, {0.0995004- 0.00998334 I, -0.995004 +
>   0.0998334 I}}
>
> Out[6]= {{(0.19802- 6.93889*10^-18 I) b +
>   b^2, (-0.980198 - 4.33681*10^-19 I) b}, {(-0.980198 -
>     4.33681*10^-19 I) b, (-0.19802 + 6.93889*10^-18 I) b + b^2}}
>
> In[7]:= Integrate[H[x], {x, 0, 1}]
>
> Out[7]= {{0.00990099 (20. b + 101. b^2), -0.980198 b}, {-0.980198 b,
>  0.00990099 (-20. b + 101. b^2)}}
>
> In[8]:= % // Dimensions
>
> Out[8]= {2, 2}
>
> In[9]:= Integrate[H[x][[1, 1]], {x, 0, 1}]
>
> Out[9]= 0.00990099 (20. b + 101. b^2)
>
> In[10]:= % // Dimensions
>
> Out[10]= {2}
>
>
> Regards,
> -- Jean-Marc
>



-- 
http://kaveh.kiewit.dartmouth.edu/


  • Prev by Date: Re: memory question
  • Next by Date: Integrating DiracDelta to get UnitStep
  • Previous by thread: Re: Piecewise function involving matrices
  • Next by thread: Solving nonlinear inequality constraints