Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.soft-sys.math.mathematica > #9322 > unrolled thread
| Started by | Andrey Demidov <andrey.demidov@gmail.com> |
|---|---|
| First post | 2012-03-31 08:46 +0000 |
| Last post | 2012-04-01 07:41 +0000 |
| Articles | 2 — 2 participants |
Back to article view | Back to comp.soft-sys.math.mathematica
Matrix operation Andrey Demidov <andrey.demidov@gmail.com> - 2012-03-31 08:46 +0000
Re: Matrix operation Murta <rodrigomurtax@gmail.com> - 2012-04-01 07:41 +0000
| From | Andrey Demidov <andrey.demidov@gmail.com> |
|---|---|
| Date | 2012-03-31 08:46 +0000 |
| Subject | Matrix operation |
| Message-ID | <jl6g9d$cp1$1@smc.vnet.net> |
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 ?
[toc] | [next] | [standalone]
| From | Murta <rodrigomurtax@gmail.com> |
|---|---|
| Date | 2012-04-01 07:41 +0000 |
| Message-ID | <jl90qt$mrr$1@smc.vnet.net> |
| In reply to | #9322 |
On Mar 31, 5:46 am, Andrey Demidov <andrey.demi...@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
[toc] | [prev] | [standalone]
Back to top | Article view | comp.soft-sys.math.mathematica
csiph-web