Honigmelone

65 Reputation

One Badge

1 years, 300 days

MaplePrimes Activity


These are replies submitted by Honigmelone

@John May Thanks, removing the ticks around the expand did the trick.

@Markiyan Hirnyk @also

Thanks very much! That worked for me. Since I don't really understand what numeric does, I will flag the fist reply as answer.

@tomleslie 

hey tomleslie,

thanks for looking into the issue. The problem was indeed in my long script. It happes that I use a variable called "a" there. When this variable is loaded before any rule using the name "a" is echoed or applied behavior becomes strange. See the attached script for reference:


restart;

rule:=abs(''a''::algebraic)^2=''a''^2;

abs('a'::algebraic)^2 = 'a'^2

(1)

someotherrule:=abs(''w''::algebraic)^2=''w''^2;

abs('w'::algebraic)^2 = 'w'^2

(2)

# applyrule(rule,abs(x)^2); #uncommenting ether of these will solve the problem

# rule;

applyrule(someotherrule,abs(x)^2); #applying a rule without "a" has no influence

x^2

(3)

a:=1; #a loaded before echoing rule

1

(4)

rule:=abs(''a''::algebraic)^2=''a''^2;

abs('a'::algebraic)^2 = 'a'^2

(5)

rule; #strange behavior

a::algebraic^2 = a^2

(6)

applyrule(rule,abs(x)^2); #cannot work as rule is diffrent from what has been defined.

abs(x)^2

(7)

 


Download applyrule_3.mw

@Preben Alsholm 

Thanks, that was what I was looking for!

@Preben Alsholm 

Thanks, I will try that!

@acer 

thanks, I appreciate all improvement suggestions for clean code:)

@Kitonum 

Just for the record: I found that even though assign also works with tables, it only works there once:


restart;

av:=<av1,av2,av3>;

av := Vector(3, {(1) = av1, (2) = av2, (3) = av3})

(1)

assign(av(1),3);

assign(av(1),5);

av1;                          #works with vectors

5

(2)

atv:=table([atv1,atv2,atv3]);

table( [( 1 ) = atv1, ( 2 ) = atv2, ( 3 ) = atv3 ] )

(3)

atvv:=convert(convert(atv,list),Vector);

atvv := Vector(3, {(1) = atv1, (2) = atv2, (3) = atv3})

(4)

assign(atvv(1),3);

assign(atvv(1),5);    

atv[1];                          #works when converting the table to vector before assigning

5

(5)

at:=table([at1,at2,at3]);

table( [( 1 ) = at1, ( 2 ) = at2, ( 3 ) = at3 ] )

(6)

assign(at[1],3);

assign(at[1],5);

Error, invalid left hand side in assignment

 

at[1];      #expected result: 5

3

(7)

 


Download assign_table.mw

 

A workaround to this is to convert the table to a vector for assigning values to the tables variables. My guess is that the tables become updated when assigning, so that the link to its variable is lost.

@Christian Wolinski 

Hey,

thank you for your second answer. To be honest I don't really understand how this function works, I am still very new at maple. But it does what it shall do. I love how you assume inside your funtion, but don't carry your assumptions to the output. That will definitely be useful later on.

However, please understand that I marked Carl Loves post as answer to this question, because his solution is a bit easier to understand.

@Carl Love 

Hey, thanks again! I would have never guessed to use a second rule. Now it works like a charm and does exactly what I wanted it to do. In order to be able to use the rule on Vectors I had to convert a bit:


restart:

f_symbol:=<abs(a-b)*abs(1,a-b),abs(b-c)*abs(1,b-c)>:  

rule:= abs(''a''::algebraic)*abs(1,''a''::algebraic)= ''a'':

rule2:= abs('expand'(-''a'')::algebraic)*abs(1, ''a''::algebraic)= ''a'':

applyrule([rule,rule2],f_symbol); #expected result: a(t)-b

Vector(2, {(1) = abs(a-b)*abs(1, a-b), (2) = abs(b-c)*abs(1, b-c)})

(1)

convert(applyrule([rule,rule2],convert(f_symbol,list)),Vector);

Vector(2, {(1) = a-b, (2) = b-c})

(2)

 

 


Download simplify_abs.mw

@Carl Love 

Hey,

thanks, that is exactly what I asked for. However I want to apply this to an expression with functions in it. I don't really understand why it does not work, as a(t)-b is also algebraic. I already tried freeze with no success:

restart:

f_symbol:=abs(a-b)*abs(1,a-b):  

f_fun:=abs(a(t)-b)*abs(1,a(t)-b);

abs(-a(t)+b)*abs(1, a(t)-b)

(1)

f_subs:=subs(a(t)=freeze(a(t)),f_fun);

abs(-`freeze/R0`+b)*abs(1, `freeze/R0`-b)

(2)

rule:= abs(''a''::algebraic)*abs(1,''a''::algebraic)= ''a'':

applyrule(rule,f_fun); #expected result: a(t)-b

abs(-a(t)+b)*abs(1, a(t)-b)

(3)

applyrule(rule,f_subs);

abs(-`freeze/R0`+b)*abs(1, `freeze/R0`-b)

(4)

thaw(%);               #expected result: a(t)-b

abs(-a(t)+b)*abs(1, a(t)-b)

(5)

applyrule(rule,f_symbol);        #works

a-b

(6)

type(''a(t)-b'',algebraic);

true

(7)

 

 


Download simplify_abs.mw

 

@Thomas Richard 

hey, thanks for your solution! The warning to the symbolic options is pretty scary, but since I only have real variables and functions I don't have to worry.

@Christian Wolinski 

hey thanks for your solution. I tested it a bit and I found a strange behaviour. Most of the times it already seems to work without assume and simplify, but see for yourself:


restart:

f_symbol:=abs(a-b)*abs(1,a-b);

abs(a-b)*abs(1, a-b)

(1)

convert(f_symbol,signum);                                   #works

a-b

(2)

f_plus:=abs(a(t)+b)*abs(1,a(t)+b);

abs(a(t)+b)*abs(1, a(t)+b)

(3)

(convert(f_plus,signum));                                   #works

a(t)+b

(4)

f_minus:=abs(a(t)-b)*abs(1,a(t)-b);

 

abs(-a(t)+b)*abs(1, a(t)-b)

(5)

# assume(a(t),real,b,real);                                 #it always works with this assumption

c:=simplify(simplify(simplify(convert(f_minus,signum))));   #expected result: a(t)-b

abs(-a(t)+b)*signum(a(t)-b)

(6)

simplify(c);                                                #???????

a(t)-b

(7)

simplify(f_minus,symbolic);

a(t)-b

(8)

 


Download simplify_abs.mw

@Kitonum 

thank you for your answer! Your addition works for me.

@acer 

thanks for your answers, I guess I missunderstood the assume facility. Yes I use Maple 18.

@tomleslie 

Well I agree that if you set b(t):= 0 this means that b(t) equals 0 for all t  and thus diff(b(t),t) is zero for all t too. However in some situations you might want to evaluate an expression at a t0 for which you know that b(t0):=0 but eval(diff(b(t),t),t0) is whatever. So we are discussing difrent points here I guess. If you know any better way to tell maple that a funktion has a specified value at a given value of its argument but not for all values you might have the better solution for OP's problem.

OP wants the result a(t)*(diff(b(t), t))  and that is exactly the result of my answer.

1 2 Page 1 of 2