Duncan Marshall
Duncan Marshall

Reputation: 550

How to I assign the output of a function to a variable in Maxima?

I have the following script:

(%i45)  g(x):=(2*x^4-5*x^3+4);
(%o45)  g(x):=2*x^4-5*x^3+4
(%i46)  dg(x):= diff(g(x), x);
(%o46)  dg(x):='diff(g(x),x,1)
(%i49)  a: find_root(dg(x), x, 1, 5);
(a) 1.875
(%i55)  g(a);
(%o55)  -4.23974609375
(%i54)  b: g(a);
(b)  g(1.875)

As you see, a is a variable, and it is assigned the numeric output of find_root(...). g(a) outputs the value of g(x) at a. However, when I try to assign that number to b, b is assigned the function g(1.875).

How can I get b to accept the numeric output?

Upvotes: 1

Views: 540

Answers (1)

Robert Dodier
Robert Dodier

Reputation: 17576

Hmm, I don't see that behavior. b is assigned a numeric value as expected. I am working with a current development version (5.46 plus additional changes since then).

(%i2) g(x):=(2*x^4-5*x^3+4);
                                4      3
(%o2)                g(x) := 2 x  - 5 x  + 4
(%i3) dg(x):= diff(g(x), x);
(%o3)                dg(x) := diff(g(x), x)
(%i4) a: find_root(dg(x), x, 1, 5);
(%o4)                         1.875
(%i5) g(a);
(%o5)                    - 4.23974609375
(%i6) b: g(a);
(%o6)                    - 4.23974609375
(%i7) b;
(%o7)                    - 4.23974609375

I am using the command line Maxima (i.e., maxima) instead of wxMaxima. Do I understand correctly that you are using wxMaxima? If so it would help others understand what's going on if you can post the .wxmx file in some way.

Upvotes: 1

Related Questions