## 68 Reputation

15 years, 216 days

## Thanks for the offer...

Thanks for the offer Doug!
I'm trying to do something to each element of a vector. I'm more used to using things like matlab, my instinct was to loop over each element ie

j=9;

for k from 1 to j do

elementNew[k]=(some operation)*element[k];

end do:

Is there a way to do the same operation to each element of a vector without using a loop?

My actual example is a bit complicated and people seem to have trouble understanding what I mean, this is it here:

http://www.mapleprimes.com/forum/factorsimplifyverylongexpression

I have a 3x3 matrix of very long expressions and want to simplify them. I converted my 3x3 matrix to a 1x9 vector and looped as above.
Its working fine now but looks a bit messy For the sake of elegance is there a neater way?

Thanks,
Kate

## Thanks for the offer...

Thanks for the offer Doug!
I'm trying to do something to each element of a vector. I'm more used to using things like matlab, my instinct was to loop over each element ie

j=9;

for k from 1 to j do

elementNew[k]=(some operation)*element[k];

end do:

Is there a way to do the same operation to each element of a vector without using a loop?

My actual example is a bit complicated and people seem to have trouble understanding what I mean, this is it here:

http://www.mapleprimes.com/forum/factorsimplifyverylongexpression

I have a 3x3 matrix of very long expressions and want to simplify them. I converted my 3x3 matrix to a 1x9 vector and looped as above.
Its working fine now but looks a bit messy For the sake of elegance is there a neater way?

Thanks,
Kate

## That worked great, thanks!...

That worked great, thanks!

## That worked great, thanks!...

That worked great, thanks!

## Right ok, I have Maple 12,...

Right ok, I have Maple 12, any suggestions for that?

Thanks,

Kate

## Right ok, I have Maple 12,...

Right ok, I have Maple 12, any suggestions for that?

Thanks,

Kate

## Thanks a million jakubi,...

Thanks a million jakubi, that's exactly what I was looking for!

I seem to be having a problem with the convert command thoughinstead of returning what you have above, it returns this:

[dp*(kc+dn)*(dn-dp-kc)*dc^4, -(-dp*kc-dp*dn+dn^2)*(dn-dp-kc)*dp*dc^3, -dp*(dn-dp-kc)*(dn^2*dp-kc^3)*dc^2, (-dp^3-kc*dp^2+dn*dp^2-kp^3)*kc^3*dc, kc^3*kp^3*(dn-dp-kc)]+`~`(-kn/(dc^2*dp*(dn-dp-kc)*(dc+dp)*(dc-dn+kc)*(-kc^2+dn^2)))

which is the same as is returned by the line above it:

```simplify([op(simplify(s,size))]*~(f/denom(ex))):
[dp*(kc+dn)*(dn-dp-kc)*dc^4, -(-dp*kc-dp*dn+dn^2)*(dn-dp-kc)*dp*dc^3, -dp*(dn-dp-kc)*(dn^2*dp-kc^3)*dc^2, (-dp^3-kc*dp^2+dn*dp^2-kp^3)*kc^3*dc, kc^3*kp^3*(dn-dp-kc)]*`~`(-kn/(dc^2*dp*(dn-dp-kc)*(dc+dp)*(dc-dn+kc)*(-kc^2+dn^2)))
```

except for a plus character between the denominator and vector of numerators, it doesn't actually work it out?

Kate

## Thanks a million jakubi,...

Thanks a million jakubi, that's exactly what I was looking for!

I seem to be having a problem with the convert command thoughinstead of returning what you have above, it returns this:

[dp*(kc+dn)*(dn-dp-kc)*dc^4, -(-dp*kc-dp*dn+dn^2)*(dn-dp-kc)*dp*dc^3, -dp*(dn-dp-kc)*(dn^2*dp-kc^3)*dc^2, (-dp^3-kc*dp^2+dn*dp^2-kp^3)*kc^3*dc, kc^3*kp^3*(dn-dp-kc)]+`~`(-kn/(dc^2*dp*(dn-dp-kc)*(dc+dp)*(dc-dn+kc)*(-kc^2+dn^2)))

which is the same as is returned by the line above it:

```simplify([op(simplify(s,size))]*~(f/denom(ex))):
[dp*(kc+dn)*(dn-dp-kc)*dc^4, -(-dp*kc-dp*dn+dn^2)*(dn-dp-kc)*dp*dc^3, -dp*(dn-dp-kc)*(dn^2*dp-kc^3)*dc^2, (-dp^3-kc*dp^2+dn*dp^2-kp^3)*kc^3*dc, kc^3*kp^3*(dn-dp-kc)]*`~`(-kn/(dc^2*dp*(dn-dp-kc)*(dc+dp)*(dc-dn+kc)*(-kc^2+dn^2)))
```

except for a plus character between the denominator and vector of numerators, it doesn't actually work it out?

Kate

## Thanks for the replies,...

Thanks for the replies, sorry if I havn't been clear!

Basically I'm asking is there a way to get Maple to factorise where possible and ignore terns that won't factorise?

Obviously this example is very easy , and works

```> f := x^2+2*x+1+y;

2
f := x  + 2 x + 1 + y

> collect(f,y,factor);

2
y + (x + 1)
```
```But it still has the same problem if another term is added:
```

```> f := x^2+2*x+1+y+z;

2
f := x  + 2 x + 1 + y + z

> collect(f,y,factor);

2
x  + 2 x + 1 + y + z

```
```So if I have an expression of hundreds of terms, do I have to go through it manually and see which terms arn't going to factorise?
```
```
```
```Thanks for your help,
Kate
```
```
```
```
```
```
```
```
Its obvious for the expression above but I have loads of expressions similar to this
-kn*(-kc^3*kp^3*dc+kc^3*dc^2*dp*dn-dc^3*kc^2*dp^2-kc^3*kp^3*dp-kc^4*dp*dc^2-dc^4*kc*dp^2-dc^4*kc^2*dp-dc^3*kc*dp^3-dc^4*dn*dp^2+dc^4*dn^2*dp-dc^3*dn*dp^3+2*dc^3*dn^2*dp^2-kc^3*dc^2*dp^2-dn^3*dc^3*dp+dn^2*dc^2*dp^3-dn^3*dc^2*dp^2+dn^2*dc^3*dp*kc+dn^2*dc^2*dp^2*kc-kc^3*dp^3*dc-kc^4*dp^2*dc-kc^4*kp^3+kc^3*kp^3*dn+kc^3*dp^2*dc*dn)
/ (dc^2*dp*(-kc+dn)*(kc+dn)*(dn-dp-kc)*(dc+dp)*(dc-dn+kc))```
```It can be doneSo don't fancy going through each one!

Thanks again,
Kate

```

```

```

## Thanks for the replies,...

Thanks for the replies, sorry if I havn't been clear!

Basically I'm asking is there a way to get Maple to factorise where possible and ignore terns that won't factorise?

Obviously this example is very easy , and works

```> f := x^2+2*x+1+y;

2
f := x  + 2 x + 1 + y

> collect(f,y,factor);

2
y + (x + 1)
```
```But it still has the same problem if another term is added:
```

```> f := x^2+2*x+1+y+z;

2
f := x  + 2 x + 1 + y + z

> collect(f,y,factor);

2
x  + 2 x + 1 + y + z

```
```So if I have an expression of hundreds of terms, do I have to go through it manually and see which terms arn't going to factorise?
```
```
```
```Thanks for your help,
Kate
```
```
```
```
```
```
```
```
Its obvious for the expression above but I have loads of expressions similar to this
-kn*(-kc^3*kp^3*dc+kc^3*dc^2*dp*dn-dc^3*kc^2*dp^2-kc^3*kp^3*dp-kc^4*dp*dc^2-dc^4*kc*dp^2-dc^4*kc^2*dp-dc^3*kc*dp^3-dc^4*dn*dp^2+dc^4*dn^2*dp-dc^3*dn*dp^3+2*dc^3*dn^2*dp^2-kc^3*dc^2*dp^2-dn^3*dc^3*dp+dn^2*dc^2*dp^3-dn^3*dc^2*dp^2+dn^2*dc^3*dp*kc+dn^2*dc^2*dp^2*kc-kc^3*dp^3*dc-kc^4*dp^2*dc-kc^4*kp^3+kc^3*kp^3*dn+kc^3*dp^2*dc*dn)
/ (dc^2*dp*(-kc+dn)*(kc+dn)*(dn-dp-kc)*(dc+dp)*(dc-dn+kc))```
```It can be doneSo don't fancy going through each one!

Thanks again,
Kate

```

```

```
 Page 1 of 1
﻿