-
I posted to worthyisthelamb.info
http://worthyisthelamb.info/blog/rss.xml
worthyisthelamb.info
One of the things that’s always bothered me is that when you solve a quadratic equation in maxima, how can you extract the solutions without using the mouse?
Some context: Maxima is NOT a magazine for women. (Ha! Dumb joke here — Maxim/Maxima.) Maxima is a Computer Algebra System. <!--break--> Solving quadratic equations in Maxima is dead simple. For example, if you type:
solve( x^2+3*x+2 = 0 )
Maxima gives you a two-element list:
[x=-2,x=-1]
Unfortunately, you can’t use this list for computations. And that’s the problem. Let’s say you were to give this list a name, for example, s:
s:%
Use standard matrix notation to get at the first and second solutions:
s[1] /* returns x=-2 / s[2] / returns x=-1 */
Unfortunately, these two expressions are still useless for computations. This is where the part function comes to play. part(...,2) returns the second “part” of the expression, so that part(s[1] ,2) returns -2 and part(s[2] ,2) returns -1.
part(s[1] ,2) /* returns -2/ part(s[2] ,2) / returns -1*/
You can now assign the solutions to quadratic functions to variables and use them in computations. Enjoy!
Array ( [title] => Extracting Roots from Quadratic Equations in Maxima [permalink] => http://worthyisthelamb.info/blog/extracting-roots-in-maxima [content] =>
One of the things that’s always bothered me is that when you solve a quadratic equation in maxima, how can you extract the solutions without using the mouse?
Some context: Maxima is NOT a magazine for women. (Ha! Dumb joke here — Maxim/Maxima.) Maxima is a Computer Algebra System.
<!--break-->
Solving quadratic equations in Maxima is dead simple. For example, if you type:solve( x^2+3*x+2 = 0 )Maxima gives you a two-element list:
[x=-2,x=-1]Unfortunately, you can’t use this list for computations. And that’s the problem. Let’s say you were to give this list a name, for example, s:
s:%Use standard matrix notation to get at the first and second solutions:
s[1]
/* returns x=-2 */
s[2]/* returns x=-1 */Unfortunately, these two expressions are still useless for computations. This is where the
partfunction comes to play.part(...,2)returns the second “part” of the expression, so thatpart(s[1],2)returns -2 andpart(s[2],2)returns -1.part(s[1],2) /* returns -2*/
part(s[2],2) /* returns -1*/You can now assign the solutions to quadratic functions to variables and use them in computations. Enjoy!
[enclosures] => Array ( [0] => SimplePie_Enclosure Object ( [bitrate] => [captions] => [categories] => [channels] => [copyright] => [credits] => [description] => [duration] => [expression] => [framerate] => [handler] => [hashes] => [height] => [javascript] => js [keywords] => [lang] => [length] => [link] => [medium] => [player] => [ratings] => [restrictions] => [samplingrate] => [thumbnails] => [title] => [type] => [width] => ) ) [categories] => Array ( [0] => SimplePie_Category Object ( [term] => Math [scheme] => [label] => ) [1] => SimplePie_Category Object ( [term] => Maxima [scheme] => [label] => ) ) [tags] => Array ( [0] => Math [1] => Maxima ) [image] => ) -
I posted to worthyisthelamb.info
http://worthyisthelamb.info/blog/rss.xml
worthyisthelamb.info
Use the matrixmap and lambda functions:
matrixmap(lambda([x],function(x)),list);
For example, to apply the sin function to the list [0, 1, 2, 3]:
matrixmap(lambda([x],sin(x)),[0,1,2,3]);
Array ( [title] => How to Apply a Function to a List or Matrix in Maxima [permalink] => http://worthyisthelamb.info/blog/node/3 [content] =>
Use the
matrixmapandlambdafunctions:matrixmap(lambda([x],function(x)),list);For example, to apply the sin function to the list [0, 1, 2, 3]:
[enclosures] => Array ( [0] => SimplePie_Enclosure Object ( [bitrate] => [captions] => [categories] => [channels] => [copyright] => [credits] => [description] => [duration] => [expression] => [framerate] => [handler] => [hashes] => [height] => [javascript] => js [keywords] => [lang] => [length] => [link] => [medium] => [player] => [ratings] => [restrictions] => [samplingrate] => [thumbnails] => [title] => [type] => [width] => ) ) [categories] => Array ( [0] => SimplePie_Category Object ( [term] => Math [scheme] => [label] => ) [1] => SimplePie_Category Object ( [term] => Maxima [scheme] => [label] => ) ) [tags] => Array ( [0] => Math [1] => Maxima ) [image] => )matrixmap(lambda([x],sin(x)),[0,1,2,3]);
Page: 1
