Honigmelone

102 Reputation

8 Badges

8 years, 242 days

MaplePrimes Activity


These are questions asked by Honigmelone

Hi,

I want to apply a rule to simplify an expression. The applyrule command works, when used directly in the worksheet. When I try to use the command within a procedure, Maple throws an error I cannot decipher:

Error, (in PatternMatching:-AlgStruct:-InsertPattern) first operand of `::' must be a name

 

Here is a full demonstration worksheet:

restart:

anexp:=abs(x)^2;

abs(x)^2

(1)

simplify(anexp);

abs(x)^2

(2)

rmabssq := proc(inexp)
description "removes the abs^2 construct in an expression":
local ruleabssqared1,ruleabssqared2,outexp:
    ruleabssqared1:= abs(''a''::algebraic)^2= ''a''^2:
    ruleabssqared2:= abs('expand'(-''a'')::algebraic)^2= ''a'':
    outexp:= applyrule([ruleabssqared1,ruleabssqared2],inexp):
    return outexp:
end proc;
 

proc (inexp) local ruleabssqared1, ruleabssqared2, outexp; description "removes the abs^2 construct in an expression"; ruleabssqared1 := abs(''a''::algebraic)^2 = ''a''^2; ruleabssqared2 := abs((('expand')(-''a''))::algebraic)^2 = ''a''; outexp := applyrule([ruleabssqared1, ruleabssqared2], inexp); return outexp end proc

(3)

## does not work :(
rmabssq(anexp);

Error, (in PatternMatching:-AlgStruct:-InsertPattern) first operand of `::' must be a name

 

## works!
ruleabssqared1:= abs(''a''::algebraic)^2= ''a''^2:
ruleabssqared2:= abs('expand'(-''a'')::algebraic)^2= ''a'':
newexp:= applyrule([ruleabssqared1,ruleabssqared2],anexp);

x^2

(4)

 


 

Download applyrule_4.mw

Thanks for your help

Hey,

I want to solve this equation and looking at the plot there are at least 3 solutions. I want the greatest/smallest negative solution. Unfortunately using solve with assumptions produces no results and solve without assumptions only finds two solutions.

Can you please help me?

#select greatest negative value from solution

restart:

expr:= ax*cos(lambda)+ay*sin(lambda)-(a+b*lambda)

ax*cos(lambda)+ay*sin(lambda)-b*lambda-a

(1)

ax:=1:ay:=2:a:=0.5:b:=0.25: #examplanatory values

plot(expr)

 

 

assume(-2*Pi<lambda,lambda<0): #does not work

 

sol_lambda:=[solve(expr=0,lambda, useassumptions)];# returns empty list even though without assumption one solution is found

Warning, solutions may have been lost

 

[]

(2)

sol_lambda:=[solve(expr=0,lambda)]; #returns only two solutions even though looking at the plot 3 are there

Warning, solve may be ignoring assumptions on the input variables.

 

Warning, solutions may have been lost

 

[2.190357220, -.2688724573]

(3)

sol_l_v:=evalb~(sol_lambda<~0); #dirty workaraound

[false, true]

(4)

sol_l_add:=[ListTools:-SearchAll(true,sol_l_v)] ; #this seems overly complicated

 

[2]

(5)

lambda:=sol_lambda[sol_l_add[-1]];  #to select the last entry

 

-.2688724573

(6)

expr; #test

 

0.

(7)

 


Download select_solution.mw

Thanks!

Honigmelone

Hi,

can you please help me with the usage of applyrule? I have the following problem that I cannot isolate. I have a rule that I want to apply, but instead of applying the rule to the expression, the rule seems to be applied to itself. In an isolated worksheet everything is fine:

restart;

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

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

(1)

 

myexp:=abs(548.477146186283171377723+radius_motor*q_mot_vec_2(t)-l_wire_0[2])^2

abs(548.477146186283171377723+radius_motor*q_mot_vec_2(t)-l_wire_0[2])^2

(2)

applyrule(rule,myexp);

(548.477146186283171377723+radius_motor*q_mot_vec_2(t)-l_wire_0[2])^2

(3)

rule

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

(4)

 


Download applyrule.mw

What happens when I try to use this rule in my script is this:

restart;

#read "some_long_script.mpl":

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

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

(1)

applyrule(rule,abs(x)^2)

abs(x)^2

(2)

rule

a::algebraic^2 = a^2

(3)

 

>
 

I want to clarify, that the script that is read before applying those rules does not apply a similar rule. Also the variables rule and x were free. Can you please help me to locate the problem?

Thanks!

Honigmelone

Hey,

at some point in my maple calculations I have to read some symbolic constants because otherwise the expressions become to big. All my constants are in a range 1e-3 to 1e6 or something. No matter how exact I calculate my result always has some Numbers in the range of <1e-20 (how small they actually are varies with Digits) together with numbers 1e-3..1e6. I presume those 1e-20 are just zeros. Can I somehow tell maple to forget/drop very small numbers and assume them all to be zero?

Thanks!

Honigmelone

Hey all,

I want to symbolically differentiate a function and recalculate the result later. Here is what I have tried so far:


restart;

myexp:=dfdb+sthlong

dfdb+sthlong

(1)

b:=<b1(t),b2(t)>;

b := Vector(2, {(1) = b1(t), (2) = b2(t)})

(2)

dfdb:=Physics[diff]~(f(b),b)

dfdb := Vector(2, {(1) = (D(f))(Vector(2, {(1) = b1(t), (2) = b2(t)})), (2) = (D(f))(Vector(2, {(1) = b1(t), (2) = b2(t)}))})

(3)

f:=b->b(1)^2+b(2)

proc (b) options operator, arrow; b(1)^2+b(2) end proc

(4)

eval(myexp);  #actual result

 

 

sthlong+(Vector(2, {(1) = (D(f))(Vector(2, {(1) = b1(t), (2) = b2(t)})), (2) = (D(f))(Vector(2, {(1) = b1(t), (2) = b2(t)}))}))

(5)

dfdb:=Physics[diff]~(f(b),b):

eval(myexp); #expected result

sthlong+(Vector(2, {(1) = 2*b1(t), (2) = 1}))

(6)

 


Download physics_diff.mw

I wonder if this is even possible, or if I missunderstand something. Can you please help me?

 

Thanks

 

Honigmelone

1 2 3 Page 2 of 3