Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2012

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

Search the Archive

Re: Matrix operation

  • To: mathgroup at smc.vnet.net
  • Subject: [mg125766] Re: Matrix operation
  • From: Murta <rodrigomurtax at gmail.com>
  • Date: Sun, 1 Apr 2012 03:39:04 -0400 (EDT)
  • Delivered-to: l-mathgroup@mail-archive0.wolfram.com
  • References: <jl6g9d$cp1$1@smc.vnet.net>

On Mar 31, 5:46 am, Andrey Demidov <andrey.demi... at gmail.com> wrote:
> Hi,
>
> I have a matrix:
>
> >> s1 = {{0, 4, 3, 6, 1, 0, 0, 30}, {0, 6, 16, 8, 0, 1, 0, 256}, {0, 4, 1,
>
>     10, 0, 0, 1, 9}, {1, -2, -4, -3, 0, 0, 0, 0}}
>
> >> MatrixForm[s1]
>
> Now, I need to get another matrix (s2) where:
>
>    - s2[i, j] = s1[i, j] where i <> 4
>    - s2[i, j] = s1[i, j] + 4 * s1[i - 1, j] where i == 4
>
> What is the best way to get s2 ?

Hi Andrey
There is my suggestion.

f[i_,j_]:=If[s1[[i,j]]==4,s1[[i,j]]+Check[4s1[[i-1,j]],0]//
Quiet,s1[[i,j]]]
(s2=Table[f[i,j],{i,1,Dimensions[s1][[1]]},{j,1,Dimensions[s1]
[[2]]}])//MatrixForm


You have to take care when the element position doesn't exist. So I
used the Check, Quiet functions.
Best Regards
Murta



  • Prev by Date: Re: typesetting derivative at a value
  • Next by Date: Re: simplify Arg[E^(I x)]?
  • Previous by thread: Re: Matrix operation
  • Next by thread: Re: Matrix operation