This should be dead simple in Maxima: I have this equation 75.0*R+0.225*C=105
How can I re-express this into R?
In other words, how do I get Maxima to show me R= (105-0.225*C)/75?
#RobertDodier wrote in a comment that one uses solve to do this.
(%i1) 75.0*R+0.225*C = 105
(%o1) 75.0*R+0.225*C = 105
(%i2) solve(%,R)
rat: replaced 0.225 by 9/40 = 0.225
rat: replaced 75.0 by 75/1 = 75.0
(%o2) [R = -(3*C-1400)/1000]
(%i3) %[1]
(%o3) R = -(3*C-1400)/1000
(%o3) R = -(3*C-1400)/1000
(%i4) %,numer
(%o4) R = -0.001*(3*C-1400)
(%i5) %,expand
(%o5) R = 1.4-0.003*C
Related
Without specifying units, I can express area and volume and have Maxima show the relationship:
(%i1) areaNoUnits: area = width * length$
(%i2) volumeNoUnits: volume = area * height$
(%i3) volumeNoUnits, areaNoUnits;
(%o3) volume = height length width
(%i4) subst(areaNoUnits, volumeNoUnits);
(%o4) volume = height length width
Now I want to specify units so I will use the ezunits package.
The ` (backtick) operator is the building block of ezunits:
An expression a ` b represents a dimensional quantity, with a indicating a nondimensional quantity and b indicating the dimensional units.
When I add units to the area and volume expressions, evaluation and substitution do not work:
(%i1) load ("ezunits")$
(%i2) areaWithUnits: area ` m^2 = (width ` m) * (length ` m);
2 2
(%o2) area ` m = length width ` m
(%i3) volumeWithUnits: volume ` m^3 = (area ` m^2) * (height ` m);
3 3
(%o3) volume ` m = area height ` m
(%i4) volumeWithUnits, areaWithUnits;
3 3
(%o4) volume ` m = area height ` m
(%i5) subst(areaWithUnits, volumeWithUnits);
3 3
(%o5) volume ` m = area height ` m
The expected output is:
volumeWithUnits, areaWithUnits;
3 3
volume ` m = height length width ` m
I do not see a function in the ezunits package to do evaluation or substitution. What is the right way to do this?
I would phrase it like this:
(%i2) load (ezunits) $
(%i3) width: W ` m;
(%o3) W ` m
(%i4) length: L ` m;
(%o4) L ` m
(%i5) area: width * length;
2
(%o5) L W ` m
(%i6) height: H ` m;
(%o6) H ` m
(%i7) volume: area * height;
3
(%o7) H L W ` m
I wrote each part as conceptualname: symbolforquantity ` unit and then wrote just conceptualname in further calculations, instead of conceptualname ` unit.
The substitution you tried in %i5 didn't work because subst is a purely formal substitution -- if there isn't a literal subexpression which is the same as the substituted-for expression, it doesn't match; subst doesn't look for rearrangements or factorizations which could help make a match. There are ways to work around that, so it might be possible to make your original formulation work, but I think it's better overall to sidestep the problem and work with conceptualname and symbolforquantity ` unit.
To say a little about what more one could do with expressions like %o7 above. There are at least two ways to replace symbols H, L, and W with specific values. One is to call subst:
(%i2) load (ezunits) $
(%i3) volume: H*L*W ` m^3;
3
(%o3) H L W ` m
(%i4) subst ([L = 20, W = %pi], volume);
3
(%o4) 20 %pi H ` m
Another is to make use of ev.
(%i5) ev (volume, L = 20, W = %pi);
3
(%o5) 20 %pi H ` m
Note that at the input prompt, something, someflags, somevalues is equivalent to ev(something, someflags, somevalues).
(%i6) volume, L = 20, W = %pi;
3
(%o6) 20 %pi H ` m
This is just a convenience. Within a function, one has to say ev(...); the shorter syntax isn't understood there.
ev is often convenient, but it's generally simpler to predict what the result is going to be with subst instead.
I have the following cubic polynomial f(x)=x³ - 3 x² + x -5 for which the cubic spline should provide the exact same polynomial assuming the following data:
(-1, -10), (0,-5), (1, -6) with second derivative at the extremes f''(-1)=-12, f''(1)=0 (note that f''(x)=6x-6.)
Here the piece of code that I tried on:
/* polynomial to interpolate and data */
f(x) := x^3 - 3* x^2 + x - 5$
x0:-1$
x1:0$
x2:1$
y0:f(x0)$
y1:f(x1)$
y2:f(x2)$
p:[[x0,y0],[x1,y1],[x2,y2]]$
fpp(x) := diff(f(x),x,2);
fpp0 : at( fpp(x), [x=x0]);
fpp2 : at( fpp(x), [x=x2]);
/* here I call cspline with d1=fpp0 and dn=fpp2 */
load(interpol)$
cspline(p, d1=fpp0, dn=fpp2);
I expected the original polynomial (f(x)=x³ -3 x² + x -5) but I got the result:
(%o40) (-16*x^3-15*x^2+6*x-5)*charfun2(x,-inf,0)+(8*x^3-15*x^2+6*x-5)*charfun2(x,0,inf)
which does not agrees with the original polynomial.
Evenmore. Here is a test on the results provided by Maxima.
Code:
/* verification */
h11(x) := -16*x^3 - 15* x^2 + 6* x - 5;
h22(x) := 8* x^3 - 15*x^2 + 6* x - 5;
h11pp(x) := diff(h11(x), x, 2);
h11pp0: at( h11pp(x), [x=x0]);
h22pp(x) := diff(h22(x), x, 2);
h22pp2 : at(h22pp(x), [x=x2]);
which throws 66 and 18 as the boundary conditions, which should be instead -12 and 0.
Thanks.
It appears you've misinterpreted the arguments d1 and dn for cspline. As the description of cspline says, d1 and dn specify the first derivative for the spline at the endpoints, not the second derivative.
When I use the first derivative of f to specify the values for d1 and dn, I get the expected result:
(%i2) f(x) := x^3 - 3* x^2 + x - 5$
(%i3) [x0, x1, x2]: [-1, 0, 1] $
(%i4) [y0, y1, y2]: map (f, %);
(%o4) [- 10, - 5, - 6]
(%i5) p: [[x0, y0], [x1, y1], [x2, y2]];
(%o5) [[- 1, - 10], [0, - 5], [1, - 6]]
(%i6) load (interpol) $
(%i7) cspline (p, d1 = at(diff(f(x), x), x=x0), dn = at(diff(f(x), x), x=x2));
3 2
(%o7) (x - 3 x + x - 5) charfun2(x, minf, 0)
3 2
+ (x - 3 x + x - 5) charfun2(x, 0, inf)
I want to display the partial derivative df/dx of f(x,y) = ln(y-1-x^2)-xy^2.
A comparable example for what I want is:
(%i0) f(x) := x^8$
(%i1) diff(f(x),x);
(%o1) 8*x^7
I've tried:
(%i1) f(x,y):=ln(y-1-x^2)-xy^2$
(%i2) g(x,y):=(diff(f(x,y), x));
(%o2) g(x,y):='diff(f(x,y),x,1)
(%i3) g(x,y):=''(diff(f(x,y), x));
(%o3) g(x,y):='diff(ln(y-x^2-1),x,1)
But it doesn't work (the summand -xy^2 got deleted?).
I want the derivated function. Something like this:
(2*x)
g(x,y):= ——————————— - y^2
(1 + x^2 - y)
the problem with your funciotn is that xy^2 instead of x*y^2for maxima is a variable you should write it as follows:
(%i5) f(x,y):=ln(y-1-x^2)-x*y^2;
(\%o5) f\left(x , \linebreak[0]y\right):=\mathrm{ln}\left(y-1-x^2\right)-x\,y^2
(%i6) diff(f(x,y), x);
(\%o6) \ifracd{d}{d\,x}\,\mathrm{ln}\left(y-x^2-1\right)-y^2
When I try to do this:
(%i1) declare (z, complex);
(%o1) done
(%i2) eq1: z^3 + 3 * %i * conjugate(z) = 0;
3
(%o2) 3 %i conjugate(z) + z = 0
(%i3) solve(eq1, z);
1/6 5/6 1/3 1/3
(- 1) (3 %i - 3 ) conjugate(z)
(%o3) [z = - -----------------------------------------,
2
1/6 5/6 1/3 1/3
(- 1) (3 %i + 3 ) conjugate(z)
z = -----------------------------------------,
2
1/6 1/3 1/3
z = - (- 1) 3 conjugate(z) ]
conjugates are not simplified. And the solution for z in terms of z isn't very useful. Is there a way to simplify it?
Also, how can I simplify out the (-1)^(1/6) part?
Also, this equation clearly has 0 as its root, but it's not in the solution set, why?
I don't think solve knows anything about conjugate. Try this to solve it with the real and imaginary parts of z as two variables. Like this:
(%i2) declare ([zr, zi], real) $
(%i3) z : zr + %i*zi $
(%i4) eq1: z^3 + 3 * %i * conjugate(z) = 0;
(%o4) (zr+%i*zi)^3+3*%i*(zr-%i*zi) = 0
(%i5) solve (eq1, [zr, zi]);
(%o5) [[zr = %r1,
zi = (sqrt(9*%r1^2-%i)+3*%r1)^(1/3)-%i/(sqrt(9*%r1^2-%i)+3*%r1)^(1/3)
+%i*%r1],
[zr = %r2,
zi = ((sqrt(3)*%i)/2-1/2)*(sqrt(9*%r2^2-%i)+3*%r2)^(1/3)
-(%i*((-(sqrt(3)*%i)/2)-1/2))/(sqrt(9*%r2^2-%i)+3*%r2)^(1/3)
+%i*%r2],
[zr = %r3,
zi = ((-(sqrt(3)*%i)/2)-1/2)*(sqrt(9*%r3^2-%i)+3*%r3)^(1/3)
-(%i*((sqrt(3)*%i)/2-1/2))/(sqrt(9*%r3^2-%i)+3*%r3)^(1/3)+%i*%r3]]
Note the variables%r1, %r2, and %r3 in the solution. These represent arbitrary values.
How can I tell Maxima to solve the following problem? (The "solve" part):
I did:
load(distrib);
fpprec: 100;
bftorat:true;
solve(2*bfloat(cdf_normal(x,0,1))-1=0.99999999999999999968130594071b0, [x]);
%,numer
Got:
(%o1) "/usr/share/maxima/5.32.1/share/distrib/distrib.mac"
(%o2) 100
(%o3) true
`rat' replaced -1.99999999999999999968130594071B0 by -199999999999999999968130594071/100000000000000000000000000000 = -1.99999999999999999968130594071B0
`rat' replaced 5.0B-1 by 1/2 = 5.0B-1
`rat' replaced 5.0B-1 by 1/2 = 5.0B-1
`rat' replaced 7.071067811865475244008443621048490392848359376884740365883398689953662392310535194251937671638207864B-1 by 118807941462947422469655519336079782367473013592460/168019802134529020067676914738440478110633605571601 = 7.071067811865475244008443621048490392848359376884740365883398689953662392310535194251937671638207864B-1
`rat' replaced 7.071067811865475244008443621048490392848359376884740365883398689953662392310535194251937671638207864B-1 by 118807941462947422469655519336079782367473013592460/168019802134529020067676914738440478110633605571601 = 7.071067811865475244008443621048490392848359376884740365883398689953662392310535194251937671638207864B-1
(%o4) [x=
(168019802134529020067676914738440478110633605571601*inverse_erf(99999999999999999968130594071/100000000000000000000000000000))/118807941462947422469655519336079782367473013592460]
inverse_erf: inverse_erf(1.0) is undefined.
-- an error. To debug this try: debugmode(true);
Further tried (to see if the rational replacement affects inverse_erf):
inverse_erf(9.9999999999999999968130594071b−1);
gamma_incomplete: continued fractions failed for gamma_incomplete(5.0b-1, 1.675965338889773975600843228854238162008399514002414970690458801529039878850010279559673197036592113916729947593696740535214189646774061729913734402353264492788885098143556404059170138591463120333687838496039284224858192931635551067412157341539627014907074717352945374476804912353312948754404927014555821149803440423871160460111635311071245528519256957555845418916034380535359079516879576795825857468710891474077746896341697834315575814989209244705740463652472196503944998297956825510866851943203353716451062616549067258800559231646552924469724160521456041856694702333938138297284123098699530288993519920353577729741393726951293645734447176179175560311787410907660921783058989196733914852345086206761158383783714360001646880454976428470630991611033582649957934844195398077660932657131767136966243415075424193909691302431604307524134764326959890911322928113456129784004060990585972427799869290459688878023964671879763390452043333273689436077956597199441415992202082578463153853017929328667898523224007b0).
-- an error. To debug this try: debugmode(true);
My advice is to try to solve the equation with a symbolic value and replace it with a numerical value later on. Here's what I get:
(%i1) load (distrib) $
(%i2) fpprec : 100 $
(%i3) solve (2 * cdf_normal (x, 0, 1) - 1 = a, x);
(%o3) [x = sqrt(2) inverse_erf(a)]
(%i4) %, a = 0.99999999999999999968130594071b0;
(%o4) [x = 6.33712711592763726142078700288254243769449484599872720866948195829\
6543071614144180808554952052800789b0 sqrt(2)]
(%i5) bfloat (%);
(%o5) [x = 8.96205111382716157629734310948891265577140990195458570850348910814\
5354833288951128435123731428126303b0]
Actually, after a bit of further study, replacing:
%,numer
with
%,bfloat
at the end of the original problem does the trick. I thought numer works with bfloats, but it only uses rational approximations, and that is why I received errors. However, using bfloat gives the correct answer.