Items tagged with if

I really want to use if condition inside of eval and sum, example as below:

sum(eval(y=x^(j),(if j=1 then x=2 else x=3 fi)),j=1..2)

The reason is: the value of x to be evaluated depends on the value of j which differs inside of the sum (in the context of B-spline functions).

Any lights? Thanks,

I have a function that is defined by a proc command including some conditional statements (if ... then ...). The conditions are so long so that I can not use a piecewise function instead of using proc. The commands in my code are long and I simplify my question as follows:
f := proc(x) local r; r := sin(x)+x*cos(x); if abs(r) < 1/2 then sin(x) else cos(x) end if; end proc;

plot('f'(x), x = -1 .. 1) works fine but the command int(('f')(x), x = -1 .. 1) gives an error:
Error, (in f) cannot determine if this expression is true or false: abs(sin(x)+x*cos(x)) < 1/2

Is there any way (except rewriting the function as a piecewise function) to get rid of the error? 

Any help is appreciated.

I have attached the problem here. I need to say sorry, because I did not provide the whole code. So, automatically It will be error if you execute it.

If you see the attachement, you will see "Result_Eva_GB_X2[3] := []". It makes a problem if I want to make comparison. So I want the result of "Result_Eva_GB_X2[3] := []" is [0].

Actually the result of Result_Eva_GB_X2[3] := [] is complex number, because I did not want the complex I made select(x->is(0<x<1)....) to eliminate the complex number and negative result. So the question is How do I make the result of Result_Eva_GB_X2[3] := [] is [0]?

I have tried to add "Selection Statement (if)" (If the result is Undefined ([]) then Result_Eva_GB_X2[3] := [0]) But it can not work. Or maybe the selection statement that I made was wrong.

Please Help me. Thank You very much

2Ask.mw

I have upload the attachment here. in this problem I want to find the comparison. Please check it and please tell me the correction

 

Ask.mw

So below is a calculation im trying to create, but it just tells me there is an unexpected IF error, and returns me to the third For line. I have tried it straight and as a procedure but i just cant seem to get it to work. Any ideas or tweaks to make this work would be much appreciated. All of the other variables I've named work in their respective lines of code, which I have left out as it is long as it is!


ComlexAlgorithm:= proc(L)
local N, j, kf, o, DeltaMag, DeltaBond;
global NConfig, Configz1, Col, Row, OldConfig, NewConfig, NewTable;

# Set Delta values to zero.
DeltaMag:=0:
DeltaBond:=0:

# Creates loops to loop through the correct changes in values i.e. Add -1, then 1 to first point, move across each point one by one, repeat from the beginning for each configuration then repeat whole process for the amount of rows.
printlevel:=4:
for N from -1 to 1 by 2 do
   for j from 1 to Col do
      for w from 0 to NConfig-1 do   
         for o from 1 to Row do

# Calculate DeltaMag.
if N=-1 then DeltaMag:=DeltaMag+1 else DeltaMag:=DeltaMag-1
end if:

# Calculate all relevant bonds i.e. 3 values for DeltaMag, except at "corner" lattice points where there is only 2 bonds.
if N= Configz1[w](o, j) then DeltaBond:= DeltaBond-1 else DeltaBond:= DeltaBond+1
end if:

if j-1>1 then
   if N <> Configz1[w](o, j+1) then DeltaBond:= DeltaBond+1
      if N = Configz1[w](o, j+1) then DeltaBond:= DeltaBond-1
else DeltaBond:= DeltaBond
end if:
end if:
end if:

if j+1<Col then
   if N <> Configz1[w](o, j+1) then DeltaBond:= DeltaBond+1
      if N = Configz1[w](o, j+1) then DeltaBond:= DeltaBond-1
else DeltaBond:= DeltaBond
end if:
end if:
end if:

# Calculate if, and by what degree, conifguration number changes using 2^(j-1) which is the arithmetric series for binary. Changes only occur when "incoming" spin is different.
if N= -1 then
   if Configz1[w](o, j) <> N then NewConfig[w]:= OldConfig[w-(2^(j-1))] 
else NewConfig[w]:= OldConfig[w]
end if:
end if:

if N= 1 then
   if Configz1[kf](o, j) <> N then NewConfig[w]:= OldConfig[w+(2^(j-1))] 
else NewConfig[kf]:= OldConfig[w]
end if:
end if:

NewTable[kf]:= [NewConfig[w], BondEnergy(w)+DeltaBond, MagEnergy(w)+DeltaMag];

# Set Delta values to zero to finsh.
DeltaMag:=0:
DeltaBond:=0:

end do:
end do:
end do:
end do:
end proc:

hello everybody, 

Is there some trick to bypass the limiited scope of the semicolon statement operator ?

More specifically, is it possible to force Maple to display (apart from the explicit use of the 'print' command) the results of the commands within two nested loops or within a loop and and a conditional statement ?


From the help page concerning statement operators it seems that it is truly impossible ...

"Note: This rule does not apply to statements enclosed in the body of another statement such as an if statement, loop, procedure, module, use statement, or try statement. In these cases, all enclosed statements must be separated by a semicolon or colon."


While not blocking it is a rather irritating limitation :-)


I wish to delete the rows that have imaginery components from my results Matrix. Have tried many variants of for loops etc.

restart

``

``

interface(displayprecision = 3)

3

(1)

(2)

``

interface(rtablesize = 81)

10

(3)

``

``

Ans := Matrix(17, 15, {(1, 1) = `-`, (1, 2) = u0, (1, 3) = u1, (1, 4) = u2, (1, 5) = u3, (1, 6) = P*x, (1, 7) = Py, (1, 8) = Pz, (1, 9) = g0, (1, 10) = g1, (1, 11) = g2, (1, 12) = g3, (1, 13) = u^2, (1, 14) = g^2, (1, 15) = P, (2, 1) = 1, (2, 2) = -.516501806300516366332207827845271720295699875, (2, 3) = .157087667438024041386330713987768482051008262*I, (2, 4) = .113781789011852812312696505223578179747798329*I, (2, 5) = -.877979905726868500805204485093148911811362591, (2, 6) = -45.5583959992909648360043286735679679113587631, (2, 7) = -49.2104104577498887775211368820566392860712299, (2, 8) = -893.5067837*I, (2, 9) = -.866146675707479268632063873487527071333386044, (2, 10) = 0.392015486681650570173437868256055772345022977e-1*I, (2, 11) = -.1411657646*I, (2, 12) = .520820958366521078324036803446408915170112964, (2, 13) = .999999999999999999999999999999999999997268842, (2, 14) = .999999999999999999999999999999999999974976375, (2, 15) = 890.986610791943203054869284606448158021303178*I, (3, 1) = 0, (3, 2) = -.516501806300516366332207827845271720295699875, (3, 3) = -.1570876674*I, (3, 4) = -.1137817890*I, (3, 5) = -.877979905726868500805204485093148911811362591, (3, 6) = 0, (3, 7) = 0, (3, 8) = 0, (3, 9) = 0, (3, 10) = 0, (3, 11) = 0, (3, 12) = 0, (3, 13) = 0, (3, 14) = 0, (3, 15) = 0, (4, 1) = 2, (4, 2) = 1.37465842397864539997343521056744950913464373, (4, 3) = -.4720070715*I, (4, 4) = 1.04887251334709968989772260444378754238846281*I, (4, 5) = -.658208509656740520048240372814155977066034431, (4, 6) = -139.935858043713569770172241394940432701557933, (4, 7) = 1009.16689416507143999697715965318783801532828, (4, 8) = 35.050637050173061427545252165933711014164793*I, (4, 9) = -1.081758215*I, (4, 10) = -.805172606177376737844957657938233921696306905, (4, 11) = 1.28822588438750284892199202326992770781607054, (4, 12) = .370982506039653923963789326359229665746676298*I, (4, 13) = 1.00000000000000000000000000000000000000004448, (4, 14) = 1.00000000000000000000000000000000000002308483, (4, 15) = 1018.21968036744599747318369866423941656487034, (5, 1) = 0, (5, 2) = 1.37465842397864539997343521056744950913464373, (5, 3) = .472007071498869469711464480852290076392886818*I, (5, 4) = -1.048872513*I, (5, 5) = -.658208509656740520048240372814155977066034431, (5, 6) = 0, (5, 7) = 0, (5, 8) = 0, (5, 9) = 0, (5, 10) = 0, (5, 11) = 0, (5, 12) = 0, (5, 13) = 0, (5, 14) = 0, (5, 15) = 0, (6, 1) = 3, (6, 2) = .888607277416217966051928947403779522572804242, (6, 3) = -.106822611437208274601612056689973427508887756, (6, 4) = .227628951666705815052303897780904267397418654, (6, 5) = -.383602784885339918445575993340862111408067307, (6, 6) = -33.2619224164850716022540679651061384838837392, (6, 7) = -70.5221377558306752001316338827006032187340768, (6, 8) = 520.235208378859672763343647578296600919428272, (6, 9) = .403127155352863813666160452061241985268802920, (6, 10) = -.229875128453580499649930605383626391667210087, (6, 11) = -.249025243344440313757976839460134436215711022, (6, 12) = .850077849442508503270095108095866473994329709, (6, 13) = .999999999999999999999999999999999999999999990, (6, 14) = 1.00000000000000000000000000000000000000001494, (6, 15) = 526.046005054204528169704406776278260629227147, (7, 1) = 0, (7, 2) = .888607277416217966051928947403779522572804242, (7, 3) = .106822611437208274601612056689973427508887756, (7, 4) = -.227628951666705815052303897780904267397418654, (7, 5) = -.383602784885339918445575993340862111408067307, (7, 6) = 0, (7, 7) = 0, (7, 8) = 0, (7, 9) = 0, (7, 10) = 0, (7, 11) = 0, (7, 12) = 0, (7, 13) = 0, (7, 14) = 0, (7, 15) = 0, (8, 1) = 4, (8, 2) = .771395089635626888037058585282289072153672569, (8, 3) = -.251315638632409886572894533969222074089643996, (8, 4) = .494467079738422222368894560870844350373447897, (8, 5) = -.311917252680552965184041884461266972741091408, (8, 6) = -35.3773974809076144493333628813387306219066392, (8, 7) = -261.955262605587133808935304231369552994540307, (8, 8) = 267.817639506339708440220037786669249266668237, (8, 9) = .542590138401669145144489319765760630956089296, (8, 10) = -.207306657051038538831939399741694104211987188, (8, 11) = -.745192226522038608473536679495983480516139685, (8, 12) = .327579665398674149197429570862493923635921752, (8, 13) = 1.00000000000000000000000000000000000000000004, (8, 14) = 1.00000000000000000000000000000000000000000070, (8, 15) = 376.295638946336949362327994692547262453058894, (9, 1) = 0, (9, 2) = .771395089635626888037058585282289072153672569, (9, 3) = .251315638632409886572894533969222074089643996, (9, 4) = -.494467079738422222368894560870844350373447897, (9, 5) = -.311917252680552965184041884461266972741091408, (9, 6) = 0, (9, 7) = 0, (9, 8) = 0, (9, 9) = 0, (9, 10) = 0, (9, 11) = 0, (9, 12) = 0, (9, 13) = 0, (9, 14) = 0, (9, 15) = 0, (10, 1) = 5, (10, 2) = -.771395089635626888037058585282289072153672569, (10, 3) = -.251315638632409886572894533969222074089643996, (10, 4) = .494467079738422222368894560870844350373447897, (10, 5) = .311917252680552965184041884461266972741091408, (10, 6) = -35.3773974809076144493333628813387306219066392, (10, 7) = -261.955262605587133808935304231369552994540307, (10, 8) = -267.817639506339708440220037786669249266668237, (10, 9) = .542590138401669145144489319765760630956089296, (10, 10) = .207306657051038538831939399741694104211987188, (10, 11) = .745192226522038608473536679495983480516139685, (10, 12) = .327579665398674149197429570862493923635921752, (10, 13) = 1.00000000000000000000000000000000000000000004, (10, 14) = 1.00000000000000000000000000000000000000000070, (10, 15) = 376.295638946336949362327994692547262453058894, (11, 1) = 0, (11, 2) = -.771395089635626888037058585282289072153672569, (11, 3) = .251315638632409886572894533969222074089643996, (11, 4) = -.494467079738422222368894560870844350373447897, (11, 5) = .311917252680552965184041884461266972741091408, (11, 6) = 0, (11, 7) = 0, (11, 8) = 0, (11, 9) = 0, (11, 10) = 0, (11, 11) = 0, (11, 12) = 0, (11, 13) = 0, (11, 14) = 0, (11, 15) = 0, (12, 1) = 6, (12, 2) = -.888607277416217966051928947403779522572804242, (12, 3) = -.106822611437208274601612056689973427508887756, (12, 4) = .227628951666705815052303897780904267397418654, (12, 5) = .383602784885339918445575993340862111408067307, (12, 6) = -33.2619224164850716022540679651061384838837392, (12, 7) = -70.5221377558306752001316338827006032187340768, (12, 8) = -520.235208378859672763343647578296600919428272, (12, 9) = .403127155352863813666160452061241985268802920, (12, 10) = .229875128453580499649930605383626391667210087, (12, 11) = .249025243344440313757976839460134436215711022, (12, 12) = .850077849442508503270095108095866473994329709, (12, 13) = .999999999999999999999999999999999999999999990, (12, 14) = 1.00000000000000000000000000000000000000001494, (12, 15) = 526.046005054204528169704406776278260629227147, (13, 1) = 0, (13, 2) = -.888607277416217966051928947403779522572804242, (13, 3) = .106822611437208274601612056689973427508887756, (13, 4) = -.227628951666705815052303897780904267397418654, (13, 5) = .383602784885339918445575993340862111408067307, (13, 6) = 0, (13, 7) = 0, (13, 8) = 0, (13, 9) = 0, (13, 10) = 0, (13, 11) = 0, (13, 12) = 0, (13, 13) = 0, (13, 14) = 0, (13, 15) = 0, (14, 1) = 7, (14, 2) = -1.37465842397864539997343521056744950913464373, (14, 3) = -.4720070715*I, (14, 4) = 1.04887251334709968989772260444378754238846281*I, (14, 5) = .658208509656740520048240372814155977066034431, (14, 6) = -139.935858043713569770172241394940432701557933, (14, 7) = 1009.16689416507143999697715965318783801532828, (14, 8) = -35.05063705*I, (14, 9) = -1.081758215*I, (14, 10) = .805172606177376737844957657938233921696306905, (14, 11) = -1.28822588438750284892199202326992770781607054, (14, 12) = .370982506039653923963789326359229665746676298*I, (14, 13) = 1.00000000000000000000000000000000000000004448, (14, 14) = 1.00000000000000000000000000000000000002308483, (14, 15) = 1018.21968036744599747318369866423941656487034, (15, 1) = 0, (15, 2) = -1.37465842397864539997343521056744950913464373, (15, 3) = .472007071498869469711464480852290076392886818*I, (15, 4) = -1.048872513*I, (15, 5) = .658208509656740520048240372814155977066034431, (15, 6) = 0, (15, 7) = 0, (15, 8) = 0, (15, 9) = 0, (15, 10) = 0, (15, 11) = 0, (15, 12) = 0, (15, 13) = 0, (15, 14) = 0, (15, 15) = 0, (16, 1) = 8, (16, 2) = .516501806300516366332207827845271720295699875, (16, 3) = .157087667438024041386330713987768482051008262*I, (16, 4) = .113781789011852812312696505223578179747798329*I, (16, 5) = .877979905726868500805204485093148911811362591, (16, 6) = -45.5583959992909648360043286735679679113587631, (16, 7) = -49.2104104577498887775211368820566392860712299, (16, 8) = 893.506783720169698656724304667952267191687315*I, (16, 9) = -.866146675707479268632063873487527071333386044, (16, 10) = -0.3920154867e-1*I, (16, 11) = .141165764599481508540163197537118257205129796*I, (16, 12) = .520820958366521078324036803446408915170112964, (16, 13) = .999999999999999999999999999999999999997268842, (16, 14) = .999999999999999999999999999999999999974976375, (16, 15) = 890.986610791943203054869284606448158021303178*I, (17, 1) = 0, (17, 2) = .516501806300516366332207827845271720295699875, (17, 3) = -.1570876674*I, (17, 4) = -.1137817890*I, (17, 5) = .877979905726868500805204485093148911811362591, (17, 6) = 0, (17, 7) = 0, (17, 8) = 0, (17, 9) = 0, (17, 10) = 0, (17, 11) = 0, (17, 12) = 0, (17, 13) = 0, (17, 14) = 0, (17, 15) = 0})

Ans := Matrix(17, 15, {(1, 1) = `-`, (1, 2) = u0, (1, 3) = u1, (1, 4) = u2, (1, 5) = u3, (1, 6) = P*x, (1, 7) = Py, (1, 8) = Pz, (1, 9) = g0, (1, 10) = g1, (1, 11) = g2, (1, 12) = g3, (1, 13) = u^2, (1, 14) = g^2, (1, 15) = P, (2, 1) = 1, (2, 2) = -.516501806300516366332207827845271720295699875, (2, 3) = .157087667438024041386330713987768482051008262*I, (2, 4) = .113781789011852812312696505223578179747798329*I, (2, 5) = -.877979905726868500805204485093148911811362591, (2, 6) = -45.5583959992909648360043286735679679113587631, (2, 7) = -49.2104104577498887775211368820566392860712299, (2, 8) = -893.5067837*I, (2, 9) = -.866146675707479268632063873487527071333386044, (2, 10) = 0.392015486681650570173437868256055772345022977e-1*I, (2, 11) = -.1411657646*I, (2, 12) = .520820958366521078324036803446408915170112964, (2, 13) = .999999999999999999999999999999999999997268842, (2, 14) = .999999999999999999999999999999999999974976375, (2, 15) = 890.986610791943203054869284606448158021303178*I, (3, 1) = 0, (3, 2) = -.516501806300516366332207827845271720295699875, (3, 3) = -.1570876674*I, (3, 4) = -.1137817890*I, (3, 5) = -.877979905726868500805204485093148911811362591, (3, 6) = 0, (3, 7) = 0, (3, 8) = 0, (3, 9) = 0, (3, 10) = 0, (3, 11) = 0, (3, 12) = 0, (3, 13) = 0, (3, 14) = 0, (3, 15) = 0, (4, 1) = 2, (4, 2) = 1.37465842397864539997343521056744950913464373, (4, 3) = -.4720070715*I, (4, 4) = 1.04887251334709968989772260444378754238846281*I, (4, 5) = -.658208509656740520048240372814155977066034431, (4, 6) = -139.935858043713569770172241394940432701557933, (4, 7) = 1009.16689416507143999697715965318783801532828, (4, 8) = 35.050637050173061427545252165933711014164793*I, (4, 9) = -1.081758215*I, (4, 10) = -.805172606177376737844957657938233921696306905, (4, 11) = 1.28822588438750284892199202326992770781607054, (4, 12) = .370982506039653923963789326359229665746676298*I, (4, 13) = 1.00000000000000000000000000000000000000004448, (4, 14) = 1.00000000000000000000000000000000000002308483, (4, 15) = 1018.21968036744599747318369866423941656487034, (5, 1) = 0, (5, 2) = 1.37465842397864539997343521056744950913464373, (5, 3) = .472007071498869469711464480852290076392886818*I, (5, 4) = -1.048872513*I, (5, 5) = -.658208509656740520048240372814155977066034431, (5, 6) = 0, (5, 7) = 0, (5, 8) = 0, (5, 9) = 0, (5, 10) = 0, (5, 11) = 0, (5, 12) = 0, (5, 13) = 0, (5, 14) = 0, (5, 15) = 0, (6, 1) = 3, (6, 2) = .888607277416217966051928947403779522572804242, (6, 3) = -.106822611437208274601612056689973427508887756, (6, 4) = .227628951666705815052303897780904267397418654, (6, 5) = -.383602784885339918445575993340862111408067307, (6, 6) = -33.2619224164850716022540679651061384838837392, (6, 7) = -70.5221377558306752001316338827006032187340768, (6, 8) = 520.235208378859672763343647578296600919428272, (6, 9) = .403127155352863813666160452061241985268802920, (6, 10) = -.229875128453580499649930605383626391667210087, (6, 11) = -.249025243344440313757976839460134436215711022, (6, 12) = .850077849442508503270095108095866473994329709, (6, 13) = .999999999999999999999999999999999999999999990, (6, 14) = 1.00000000000000000000000000000000000000001494, (6, 15) = 526.046005054204528169704406776278260629227147, (7, 1) = 0, (7, 2) = .888607277416217966051928947403779522572804242, (7, 3) = .106822611437208274601612056689973427508887756, (7, 4) = -.227628951666705815052303897780904267397418654, (7, 5) = -.383602784885339918445575993340862111408067307, (7, 6) = 0, (7, 7) = 0, (7, 8) = 0, (7, 9) = 0, (7, 10) = 0, (7, 11) = 0, (7, 12) = 0, (7, 13) = 0, (7, 14) = 0, (7, 15) = 0, (8, 1) = 4, (8, 2) = .771395089635626888037058585282289072153672569, (8, 3) = -.251315638632409886572894533969222074089643996, (8, 4) = .494467079738422222368894560870844350373447897, (8, 5) = -.311917252680552965184041884461266972741091408, (8, 6) = -35.3773974809076144493333628813387306219066392, (8, 7) = -261.955262605587133808935304231369552994540307, (8, 8) = 267.817639506339708440220037786669249266668237, (8, 9) = .542590138401669145144489319765760630956089296, (8, 10) = -.207306657051038538831939399741694104211987188, (8, 11) = -.745192226522038608473536679495983480516139685, (8, 12) = .327579665398674149197429570862493923635921752, (8, 13) = 1.00000000000000000000000000000000000000000004, (8, 14) = 1.00000000000000000000000000000000000000000070, (8, 15) = 376.295638946336949362327994692547262453058894, (9, 1) = 0, (9, 2) = .771395089635626888037058585282289072153672569, (9, 3) = .251315638632409886572894533969222074089643996, (9, 4) = -.494467079738422222368894560870844350373447897, (9, 5) = -.311917252680552965184041884461266972741091408, (9, 6) = 0, (9, 7) = 0, (9, 8) = 0, (9, 9) = 0, (9, 10) = 0, (9, 11) = 0, (9, 12) = 0, (9, 13) = 0, (9, 14) = 0, (9, 15) = 0, (10, 1) = 5, (10, 2) = -.771395089635626888037058585282289072153672569, (10, 3) = -.251315638632409886572894533969222074089643996, (10, 4) = .494467079738422222368894560870844350373447897, (10, 5) = .311917252680552965184041884461266972741091408, (10, 6) = -35.3773974809076144493333628813387306219066392, (10, 7) = -261.955262605587133808935304231369552994540307, (10, 8) = -267.817639506339708440220037786669249266668237, (10, 9) = .542590138401669145144489319765760630956089296, (10, 10) = .207306657051038538831939399741694104211987188, (10, 11) = .745192226522038608473536679495983480516139685, (10, 12) = .327579665398674149197429570862493923635921752, (10, 13) = 1.00000000000000000000000000000000000000000004, (10, 14) = 1.00000000000000000000000000000000000000000070, (10, 15) = 376.295638946336949362327994692547262453058894, (11, 1) = 0, (11, 2) = -.771395089635626888037058585282289072153672569, (11, 3) = .251315638632409886572894533969222074089643996, (11, 4) = -.494467079738422222368894560870844350373447897, (11, 5) = .311917252680552965184041884461266972741091408, (11, 6) = 0, (11, 7) = 0, (11, 8) = 0, (11, 9) = 0, (11, 10) = 0, (11, 11) = 0, (11, 12) = 0, (11, 13) = 0, (11, 14) = 0, (11, 15) = 0, (12, 1) = 6, (12, 2) = -.888607277416217966051928947403779522572804242, (12, 3) = -.106822611437208274601612056689973427508887756, (12, 4) = .227628951666705815052303897780904267397418654, (12, 5) = .383602784885339918445575993340862111408067307, (12, 6) = -33.2619224164850716022540679651061384838837392, (12, 7) = -70.5221377558306752001316338827006032187340768, (12, 8) = -520.235208378859672763343647578296600919428272, (12, 9) = .403127155352863813666160452061241985268802920, (12, 10) = .229875128453580499649930605383626391667210087, (12, 11) = .249025243344440313757976839460134436215711022, (12, 12) = .850077849442508503270095108095866473994329709, (12, 13) = .999999999999999999999999999999999999999999990, (12, 14) = 1.00000000000000000000000000000000000000001494, (12, 15) = 526.046005054204528169704406776278260629227147, (13, 1) = 0, (13, 2) = -.888607277416217966051928947403779522572804242, (13, 3) = .106822611437208274601612056689973427508887756, (13, 4) = -.227628951666705815052303897780904267397418654, (13, 5) = .383602784885339918445575993340862111408067307, (13, 6) = 0, (13, 7) = 0, (13, 8) = 0, (13, 9) = 0, (13, 10) = 0, (13, 11) = 0, (13, 12) = 0, (13, 13) = 0, (13, 14) = 0, (13, 15) = 0, (14, 1) = 7, (14, 2) = -1.37465842397864539997343521056744950913464373, (14, 3) = -.4720070715*I, (14, 4) = 1.04887251334709968989772260444378754238846281*I, (14, 5) = .658208509656740520048240372814155977066034431, (14, 6) = -139.935858043713569770172241394940432701557933, (14, 7) = 1009.16689416507143999697715965318783801532828, (14, 8) = -35.05063705*I, (14, 9) = -1.081758215*I, (14, 10) = .805172606177376737844957657938233921696306905, (14, 11) = -1.28822588438750284892199202326992770781607054, (14, 12) = .370982506039653923963789326359229665746676298*I, (14, 13) = 1.00000000000000000000000000000000000000004448, (14, 14) = 1.00000000000000000000000000000000000002308483, (14, 15) = 1018.21968036744599747318369866423941656487034, (15, 1) = 0, (15, 2) = -1.37465842397864539997343521056744950913464373, (15, 3) = .472007071498869469711464480852290076392886818*I, (15, 4) = -1.048872513*I, (15, 5) = .658208509656740520048240372814155977066034431, (15, 6) = 0, (15, 7) = 0, (15, 8) = 0, (15, 9) = 0, (15, 10) = 0, (15, 11) = 0, (15, 12) = 0, (15, 13) = 0, (15, 14) = 0, (15, 15) = 0, (16, 1) = 8, (16, 2) = .516501806300516366332207827845271720295699875, (16, 3) = .157087667438024041386330713987768482051008262*I, (16, 4) = .113781789011852812312696505223578179747798329*I, (16, 5) = .877979905726868500805204485093148911811362591, (16, 6) = -45.5583959992909648360043286735679679113587631, (16, 7) = -49.2104104577498887775211368820566392860712299, (16, 8) = 893.506783720169698656724304667952267191687315*I, (16, 9) = -.866146675707479268632063873487527071333386044, (16, 10) = -0.3920154867e-1*I, (16, 11) = .141165764599481508540163197537118257205129796*I, (16, 12) = .520820958366521078324036803446408915170112964, (16, 13) = .999999999999999999999999999999999999997268842, (16, 14) = .999999999999999999999999999999999999974976375, (16, 15) = 890.986610791943203054869284606448158021303178*I, (17, 1) = 0, (17, 2) = .516501806300516366332207827845271720295699875, (17, 3) = -.1570876674*I, (17, 4) = -.1137817890*I, (17, 5) = .877979905726868500805204485093148911811362591, (17, 6) = 0, (17, 7) = 0, (17, 8) = 0, (17, 9) = 0, (17, 10) = 0, (17, 11) = 0, (17, 12) = 0, (17, 13) = 0, (17, 14) = 0, (17, 15) = 0})

(4)

``

(5)

"seq( if 'has'(Ans(n,1..15) ,Im<>0) then DeleteRow (Ans(n) )end if,n=2..17)"

Error, invalid argument sequence

"seq( if 'has'(Ans(n,1..15) ,Im<>0) then DeleteRow (Ans(n) )end if,n=2..17)"

 

Ans

Matrix(17, 15, {(1, 1) = `-`, (1, 2) = u0, (1, 3) = u1, (1, 4) = u2, (1, 5) = u3, (1, 6) = P*x, (1, 7) = Py, (1, 8) = Pz, (1, 9) = g0, (1, 10) = g1, (1, 11) = g2, (1, 12) = g3, (1, 13) = u^2, (1, 14) = g^2, (1, 15) = P, (2, 1) = 1, (2, 2) = -.516501806300516366332207827845271720295699875, (2, 3) = .157087667438024041386330713987768482051008262*I, (2, 4) = .113781789011852812312696505223578179747798329*I, (2, 5) = -.877979905726868500805204485093148911811362591, (2, 6) = -45.5583959992909648360043286735679679113587631, (2, 7) = -49.2104104577498887775211368820566392860712299, (2, 8) = -893.5067837*I, (2, 9) = -.866146675707479268632063873487527071333386044, (2, 10) = 0.392015486681650570173437868256055772345022977e-1*I, (2, 11) = -.1411657646*I, (2, 12) = .520820958366521078324036803446408915170112964, (2, 13) = .999999999999999999999999999999999999997268842, (2, 14) = .999999999999999999999999999999999999974976375, (2, 15) = 890.986610791943203054869284606448158021303178*I, (3, 1) = 0, (3, 2) = -.516501806300516366332207827845271720295699875, (3, 3) = -.1570876674*I, (3, 4) = -.1137817890*I, (3, 5) = -.877979905726868500805204485093148911811362591, (3, 6) = 0, (3, 7) = 0, (3, 8) = 0, (3, 9) = 0, (3, 10) = 0, (3, 11) = 0, (3, 12) = 0, (3, 13) = 0, (3, 14) = 0, (3, 15) = 0, (4, 1) = 2, (4, 2) = 1.37465842397864539997343521056744950913464373, (4, 3) = -.4720070715*I, (4, 4) = 1.04887251334709968989772260444378754238846281*I, (4, 5) = -.658208509656740520048240372814155977066034431, (4, 6) = -139.935858043713569770172241394940432701557933, (4, 7) = 1009.16689416507143999697715965318783801532828, (4, 8) = 35.050637050173061427545252165933711014164793*I, (4, 9) = -1.081758215*I, (4, 10) = -.805172606177376737844957657938233921696306905, (4, 11) = 1.28822588438750284892199202326992770781607054, (4, 12) = .370982506039653923963789326359229665746676298*I, (4, 13) = 1.00000000000000000000000000000000000000004448, (4, 14) = 1.00000000000000000000000000000000000002308483, (4, 15) = 1018.21968036744599747318369866423941656487034, (5, 1) = 0, (5, 2) = 1.37465842397864539997343521056744950913464373, (5, 3) = .472007071498869469711464480852290076392886818*I, (5, 4) = -1.048872513*I, (5, 5) = -.658208509656740520048240372814155977066034431, (5, 6) = 0, (5, 7) = 0, (5, 8) = 0, (5, 9) = 0, (5, 10) = 0, (5, 11) = 0, (5, 12) = 0, (5, 13) = 0, (5, 14) = 0, (5, 15) = 0, (6, 1) = 3, (6, 2) = .888607277416217966051928947403779522572804242, (6, 3) = -.106822611437208274601612056689973427508887756, (6, 4) = .227628951666705815052303897780904267397418654, (6, 5) = -.383602784885339918445575993340862111408067307, (6, 6) = -33.2619224164850716022540679651061384838837392, (6, 7) = -70.5221377558306752001316338827006032187340768, (6, 8) = 520.235208378859672763343647578296600919428272, (6, 9) = .403127155352863813666160452061241985268802920, (6, 10) = -.229875128453580499649930605383626391667210087, (6, 11) = -.249025243344440313757976839460134436215711022, (6, 12) = .850077849442508503270095108095866473994329709, (6, 13) = .999999999999999999999999999999999999999999990, (6, 14) = 1.00000000000000000000000000000000000000001494, (6, 15) = 526.046005054204528169704406776278260629227147, (7, 1) = 0, (7, 2) = .888607277416217966051928947403779522572804242, (7, 3) = .106822611437208274601612056689973427508887756, (7, 4) = -.227628951666705815052303897780904267397418654, (7, 5) = -.383602784885339918445575993340862111408067307, (7, 6) = 0, (7, 7) = 0, (7, 8) = 0, (7, 9) = 0, (7, 10) = 0, (7, 11) = 0, (7, 12) = 0, (7, 13) = 0, (7, 14) = 0, (7, 15) = 0, (8, 1) = 4, (8, 2) = .771395089635626888037058585282289072153672569, (8, 3) = -.251315638632409886572894533969222074089643996, (8, 4) = .494467079738422222368894560870844350373447897, (8, 5) = -.311917252680552965184041884461266972741091408, (8, 6) = -35.3773974809076144493333628813387306219066392, (8, 7) = -261.955262605587133808935304231369552994540307, (8, 8) = 267.817639506339708440220037786669249266668237, (8, 9) = .542590138401669145144489319765760630956089296, (8, 10) = -.207306657051038538831939399741694104211987188, (8, 11) = -.745192226522038608473536679495983480516139685, (8, 12) = .327579665398674149197429570862493923635921752, (8, 13) = 1.00000000000000000000000000000000000000000004, (8, 14) = 1.00000000000000000000000000000000000000000070, (8, 15) = 376.295638946336949362327994692547262453058894, (9, 1) = 0, (9, 2) = .771395089635626888037058585282289072153672569, (9, 3) = .251315638632409886572894533969222074089643996, (9, 4) = -.494467079738422222368894560870844350373447897, (9, 5) = -.311917252680552965184041884461266972741091408, (9, 6) = 0, (9, 7) = 0, (9, 8) = 0, (9, 9) = 0, (9, 10) = 0, (9, 11) = 0, (9, 12) = 0, (9, 13) = 0, (9, 14) = 0, (9, 15) = 0, (10, 1) = 5, (10, 2) = -.771395089635626888037058585282289072153672569, (10, 3) = -.251315638632409886572894533969222074089643996, (10, 4) = .494467079738422222368894560870844350373447897, (10, 5) = .311917252680552965184041884461266972741091408, (10, 6) = -35.3773974809076144493333628813387306219066392, (10, 7) = -261.955262605587133808935304231369552994540307, (10, 8) = -267.817639506339708440220037786669249266668237, (10, 9) = .542590138401669145144489319765760630956089296, (10, 10) = .207306657051038538831939399741694104211987188, (10, 11) = .745192226522038608473536679495983480516139685, (10, 12) = .327579665398674149197429570862493923635921752, (10, 13) = 1.00000000000000000000000000000000000000000004, (10, 14) = 1.00000000000000000000000000000000000000000070, (10, 15) = 376.295638946336949362327994692547262453058894, (11, 1) = 0, (11, 2) = -.771395089635626888037058585282289072153672569, (11, 3) = .251315638632409886572894533969222074089643996, (11, 4) = -.494467079738422222368894560870844350373447897, (11, 5) = .311917252680552965184041884461266972741091408, (11, 6) = 0, (11, 7) = 0, (11, 8) = 0, (11, 9) = 0, (11, 10) = 0, (11, 11) = 0, (11, 12) = 0, (11, 13) = 0, (11, 14) = 0, (11, 15) = 0, (12, 1) = 6, (12, 2) = -.888607277416217966051928947403779522572804242, (12, 3) = -.106822611437208274601612056689973427508887756, (12, 4) = .227628951666705815052303897780904267397418654, (12, 5) = .383602784885339918445575993340862111408067307, (12, 6) = -33.2619224164850716022540679651061384838837392, (12, 7) = -70.5221377558306752001316338827006032187340768, (12, 8) = -520.235208378859672763343647578296600919428272, (12, 9) = .403127155352863813666160452061241985268802920, (12, 10) = .229875128453580499649930605383626391667210087, (12, 11) = .249025243344440313757976839460134436215711022, (12, 12) = .850077849442508503270095108095866473994329709, (12, 13) = .999999999999999999999999999999999999999999990, (12, 14) = 1.00000000000000000000000000000000000000001494, (12, 15) = 526.046005054204528169704406776278260629227147, (13, 1) = 0, (13, 2) = -.888607277416217966051928947403779522572804242, (13, 3) = .106822611437208274601612056689973427508887756, (13, 4) = -.227628951666705815052303897780904267397418654, (13, 5) = .383602784885339918445575993340862111408067307, (13, 6) = 0, (13, 7) = 0, (13, 8) = 0, (13, 9) = 0, (13, 10) = 0, (13, 11) = 0, (13, 12) = 0, (13, 13) = 0, (13, 14) = 0, (13, 15) = 0, (14, 1) = 7, (14, 2) = -1.37465842397864539997343521056744950913464373, (14, 3) = -.4720070715*I, (14, 4) = 1.04887251334709968989772260444378754238846281*I, (14, 5) = .658208509656740520048240372814155977066034431, (14, 6) = -139.935858043713569770172241394940432701557933, (14, 7) = 1009.16689416507143999697715965318783801532828, (14, 8) = -35.05063705*I, (14, 9) = -1.081758215*I, (14, 10) = .805172606177376737844957657938233921696306905, (14, 11) = -1.28822588438750284892199202326992770781607054, (14, 12) = .370982506039653923963789326359229665746676298*I, (14, 13) = 1.00000000000000000000000000000000000000004448, (14, 14) = 1.00000000000000000000000000000000000002308483, (14, 15) = 1018.21968036744599747318369866423941656487034, (15, 1) = 0, (15, 2) = -1.37465842397864539997343521056744950913464373, (15, 3) = .472007071498869469711464480852290076392886818*I, (15, 4) = -1.048872513*I, (15, 5) = .658208509656740520048240372814155977066034431, (15, 6) = 0, (15, 7) = 0, (15, 8) = 0, (15, 9) = 0, (15, 10) = 0, (15, 11) = 0, (15, 12) = 0, (15, 13) = 0, (15, 14) = 0, (15, 15) = 0, (16, 1) = 8, (16, 2) = .516501806300516366332207827845271720295699875, (16, 3) = .157087667438024041386330713987768482051008262*I, (16, 4) = .113781789011852812312696505223578179747798329*I, (16, 5) = .877979905726868500805204485093148911811362591, (16, 6) = -45.5583959992909648360043286735679679113587631, (16, 7) = -49.2104104577498887775211368820566392860712299, (16, 8) = 893.506783720169698656724304667952267191687315*I, (16, 9) = -.866146675707479268632063873487527071333386044, (16, 10) = -0.3920154867e-1*I, (16, 11) = .141165764599481508540163197537118257205129796*I, (16, 12) = .520820958366521078324036803446408915170112964, (16, 13) = .999999999999999999999999999999999999997268842, (16, 14) = .999999999999999999999999999999999999974976375, (16, 15) = 890.986610791943203054869284606448158021303178*I, (17, 1) = 0, (17, 2) = .516501806300516366332207827845271720295699875, (17, 3) = -.1570876674*I, (17, 4) = -.1137817890*I, (17, 5) = .877979905726868500805204485093148911811362591, (17, 6) = 0, (17, 7) = 0, (17, 8) = 0, (17, 9) = 0, (17, 10) = 0, (17, 11) = 0, (17, 12) = 0, (17, 13) = 0, (17, 14) = 0, (17, 15) = 0})

(6)

``

``

 

Download matrix_imaginery_elements.mw

Hi guys,

 

I would like to convert a piecewise defined function of two variables into an if structure
Example :

F := (x,y) -> piecewise(x < 0, piecewise(y < 0, 0, 1), piecewise(y < 0, 1, 0));

What I expect is something like (the indentation is just for fun)
if x < 0 then
   if y < 0 then 0 else 1 end if;
else 
   if y < 0 then 1 else 0 end if;
 end if


I tried the following :

convert(F(x,y), `if`)  # but it only converts the "outer x condition" and keeps the "inner y conditions" unchanged

And next this :

map(u -> convert(u, `if`), F(x,y)):   # fails to give m
# and
map(u -> convert(u(x,y), `if`), F(x,y)): 
# ...

without success.

Can anoybody help me please.
I am also interested in an explanation of the reasons why the previous command do not work.

Thanks all

I need to do this with a sequence of a large number of elements but here is my question with a sequence of fewer elements.

a:={10,11,-13,9,20,74,10}:

I want to check each element of the sequence if it is negative. And if any element is negative I want to replace with 0 (or do something else). I tried the following code but it didn't work. 

for k from 1 to 7 do
  if (a[k]<0) then subs(a[k]=0, a) end if:
end do;

Please help me to figure it out. 

I'm new to Maple, and I come from using Matlab.  Apparently my Matlab way of thinking isn't working on Maple.  I'm trying  to ride a bit of code that simulates flipping a coin 1000 times.  The code counts one partiuclar result (1=heads) at the end prints that result.

 

Here's the code:

 

dice:=proc()

count:=0:  

for i from 1 to 10000 do  

roll := rand(1..2):  

roll:=()  

if (roll=1) then count:=count+1 end if  

end do  

print(count)  

 I get errors saying I didn't terminate my loops correctly.  Help, please.

This is the code example_hw2.mw which derives from hw2_I1.mw.

hw2_I1.mw works but example_hw2.mw doesn't work and the differences between two codes are two new function I added to the dsolve which are η(t) and I2(t). The I2(t) is the second part of I1(t) at the interval t>t* which subject to Phi(t*)=0.

So how to make the sentence 'if |(H(t))/(omega)|>1 then eta(t)=0 else eta(t)=arccos(-(H(t))/(omega))' and 'I2(t) = (int(p(t), x = -eta(t) .. eta(t)))/Pi' work?

 

I am wondering if Selection Statement 'if' can be coded in Embedded Components such as Text Area.

I have typed codes in the Text Area(%text_beta_degress) as follows:

if %text_beta_degress=1.2 then Do(%text_ps=28);Do(%text_l4=5.439);
elif %text_beta_degress=8.77 then Do(%text_ps=15);Do(%text_l4=2.785);
elif %text_beta_degress=10 then Do(%text_ps=12.83);Do(%text_l4=2.348);
elif %text_beta_degress=14.4 then Do(%text_ps=5);Do(%text_l4=0.758);
end if

When I typed 1.2 or 8.77 into the Text Area(%text_beta_degress) and tapped 'Enter', %text_ps and %text_l4 didn't response.

Is there any solution?

Hi I am not very used to Maple since I used mathematica previously.

So is there way to put an if statement within sequecne definition? that is,

 

id = 1;

seq(if(i>2, idx += 1), idx+i , i=1..10)

 

something like this where if statement runs and then idx+i is added to the sequence, as if I am running a loop.

Thanks

Page 1 of 1