Hi Mike,
FYI https://pari.math.u-bordeaux.fr/paridroid/
cheers
@@i
Op 05-11-2020 om 19:31 schreef 'Michael Day' via Programming:
FWIW,
I've played around with your (Piet's) example in J and Pari-GP, which
is free. Pari-GP doesn't
itself run on Android or iOS phones & tablets, but can be run via
SAGE as far as I understand my iPad!
The J is pretty messy and hardly general! But normal stuff...
NB. General expression for (x^2 + log y)^(+ or -1) - c
f =: 2 : 0 NB. (x^2 + log y)^m - n ## m for power +-1, n for c
:
n -~ m^~ (x^2) + ^. y
)
1 (_1 f 0.5) 3 NB. eg x=1, y=3, c = 0.5, power negative
_0.023494642
fff =: 1 & (_1 f 0.5) NB. curry? values for x = 1, power = _1, c = 0.5
fff 3 NB. same as non-curried example, as expected
_0.023494642
NB. I couldn't get deriv to work without a domain error, (my
misunderstanding probably) so:
mydfff =: 1e_7 & ((-:@+/ %~ -/@:fff) @ ,: ) NB.DIY secant approx for
dfff(y)/dy
NB. Newton-Raphson... NB needs some care on variable domains!
(] - fff % mydfff)^:(i.3) 2
2
2.137974
2.2529446
NB. N-R DOES resolve - in this case
(] - fff % mydfff)^:_] 2
2.7182818
Here's the same sort of thing in Pari GP. The solution at 17:22 %38 is
the same as my
Newton-Raphson J solution, luckily!
# help on solve Note the condition on values on a and b....
(17:14) gp > ?solve solve(X=a,b,expr): real root of expression expr (X
between a and b), where expr(a)*expr(b)<=0.
# define function
(17:21) gp > f(x,y,c,p=1)={(x^2 + log(y))^p-c} %35 =
(x,y,c,p=1)->(x^2+log(y))^p-c
# sorry, forgot to limit Pari GP's precision for this example........
(17:22) gp > solve(x=0,2,f(x,2,3)) # solve for x given y,c,p>0 %36 =
1.5188327160816805010724091402460886947
(17:22) gp > solve(x=1,2,f(x,0.5,3,-1)) # solve for x given y,c,p<0
%37 = 1.0131537464241439810906386058489161931
(17:22) gp > solve(y=2,3,f(1,y,0.5,-1)) # solve for y given x,c,p<0
%38 = 2.7182818284590452353602874713526624978
(17:22) gp > f(1,3,0.5,-1) # same as J's 1 (_1 f 0.5) 3 , shown above
%39 = -0.023494641959495592026487857212476799043
Amused me, and _might_ be of interest, but I expect something along
the lines suggested
by Pascal Jasmin would be more generally useful.
Mike
On 05/11/2020 03:58, Piet de Jong wrote:
I was hoping for more of a “J” type solution.
For example if f(x,y) = (x^2 + log y)^{-1} = c
Then given c and say x, I can solve for y. (ie write J function)
Or given c and y I can solve for x. (ie write a J function)
(I’m assuming domains etc are ok. — this is just an example.)
So instead of following this long process of finding the two
functions I was hoping in J there would be a “clean and tidy” way of
doing things.
Probably impossible even for simple functions f.
On 5 Nov 2020, at 2:24 pm, Raul Miller <[email protected]> wrote:
The answer is: sometimes yes, sometimes no.
See https://en.wikipedia.org/wiki/Equation_solving for some of the
issues.
If f can be expressed as a polynomial, you might want to consider
using https://www.jsoftware.com/help/dictionary/dpdot.htm
Thanks,
--
Raul
On Wed, Nov 4, 2020 at 7:27 PM Piet de Jong <[email protected]> wrote:
Still trying to learn/improve my J after 25 years.
Here is the issue. I’m probably having a pipe dream.
Suppose you have an implicit function f(x,y)=0 which is relatively
“clean” (ie simple to specify)
Is there a “clean/efficient” way in J to solve for y given x or
vice versa.
I know I can write a function g such that g x gives y and g^:_1 y
gives x.
But is there a cleaner way? The g and its inverse may be
complicated even if f is relatively simple.
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm