Paul,
In the original series of expressions I see that line (%i5) %phi[1] :
first(e2)$ is in error it should read.
e2: subst([x=en1, d=en2],[first(diff(e1,x)), diff(e1,x)])$
so the original series of expressions should read.
(%i1) x^2+d*y*4+d^2*(-4)$
(%i2) e1: rhs(first(solve(x^2+d*y*4+d^2*(-4),y)));
(%i3) en1: 10$
(%i4) en2: 5$
(%i5) e2: subst([x=en1, d=en2],[first(diff(e1,x)), diff(e1,x)])$
(%i6) %phi[1] : first(e2)$
(%i7) %phi[2] : second(e2)$
(%i8) [(%phi[1]*d*(-2)),(d+((%phi[1])^(2)*d*(-1)))]$
[(%phi[2]*d*(-2)),(d+((%phi[2])^(2)*d*(-1)))]$
((%pi*1/2)+(atan((((%phi[1]+(%phi[2]*(-1))))^((-1))*(1+(%phi[2]*%phi[1]))))*
(-1)));
All on line (%i8) is one expression which calculates the angle based on the
prior lines.
However running the above again you are right no need for
the first two lines of (%i8), it still produces (%i8) as an angle.
The whole objective of this procedure is to come up with
en2 value when line (%i8) equals 0.178092938.
It is important for Maxima to produce the resultant en2 value
because more code will be added such that it can recall the
resultant value of en2 to be used in further code.
The loop procedure was the only way I could see it working,
Starting with the for. while procedure getting close to
the en2 whole value and then converting over to
the newton procedure for more refinement to get
to 0.178092938 value.
If the find_root(%o8 - 0.178092938, en2, 10, 80); could
work as Robert Dodier suggest then that would be great,
as it would reduce the use of a lot of code. Currently unfortunately
the find_root wants a expression for en2 as opposed to a real number.
And en2 starts out as a real number, not an expression.
William Porter
wporter at omegapar.com
From: Paul Bowyer [mailto:pbowyer at olynet.com]
Sent: Tuesday, September 07, 2010 10:31 AM
To: William Porter; maxima at math.utexas.edu
Subject: Re: Find the angle between two tangents
William:
As I mentioned in my first reply, I didn't spend much time trying to
understand your math. I took another quick look at it this morning and I
must confess I don't understand what you are trying to do. The maxima
statements that were listed at the top of your original post:
-------------------------------------------------------
(%i1) x^2+d*y*4+d^2*(-4)$
(%i2) e1: rhs(first(solve(x^2+d*y*4+d^2*(-4),y)));
(%i3) en1: 10$
(%i4) en2: 5$
(%i5) %phi[1] : first(e2)$
(%i6) %phi[1] : first(e2)$
(%i7) %phi[2] : second(e2)$
(%i8) [(%phi[1]*d*(-2)),(d+((%phi[1])^(2)*d*(-1)))]$
[(%phi[2]*d*(-2)),(d+((%phi[2])^(2)*d*(-1)))]$
((%pi*1/2)+(atan((((%phi[1]+(%phi[2]*(-1))))^((-1))*(1+(%phi[2]*%phi[1]))))*
(-1)));
(%i9) %,numer;
-------------------------------------------------------
I changed slightly to get the results you mentioned in that post
-------------------------------------------------------
x^2+d*y*4+d^2*(-4);
e1:rhs(first(solve(x^2+d*y*4+d^2*(-4),y)));
/*Added this line from 'f1()' below*/
e2:subst([x=en1, d=en2],[first(diff(e1,x)), diff(e1,x)]);
en1: 10;
en2: 15;
/*Using %phi conflicts with a constant name maybe?? but didn't change it*/
%phi[1] : first(e2);
/*%phi[1] : first(e2); Removed this line*/
%phi[2] : second(e2);
[(%phi[1]*d*(-2)),(d+((%phi[1])^(2)*d*(-1)))];
[(%phi[2]*d*(-2)),(d+((%phi[2])^(2)*d*(-1)))];
((%pi*1/2)+(atan((((%phi[1]+(%phi[2]*(-1))))^((-1))*(1+(%phi[2]*%phi[1]))))*
(-1)));
%,numer;
-------------------------------------------------------
but after further inspection I notice that a couple of lines are not
effective
-------------------------------------------------------
x^2+d*y*4+d^2*(-4);
e1:rhs(first(solve(x^2+d*y*4+d^2*(-4),y)));
/*Added this line from 'f1()' in your post*/
e2:subst([x=en1, d=en2],[first(diff(e1,x)), diff(e1,x)]);
en1: 10;
en2: 15;
/*Using %phi conflicts with a constant name maybe?? but didn't change it*/
%phi[1] : first(e2);
/*%phi[1] : first(e2); Removed this line*/
%phi[2] : second(e2);
/*The following two lines aren't doing anything that affects the value of
the last line
[(%phi[1]*d*(-2)),(d+((%phi[1])^(2)*d*(-1)))];
[(%phi[2]*d*(-2)),(d+((%phi[2])^(2)*d*(-1)))]; */
/*This line is actually the value you are outputting*/
((%pi*1/2)+(atan((((%phi[1]+(%phi[2]*(-1))))^((-1))*(1+(%phi[2]*%phi[1]))))*
(-1)));
%,numer;
-------------------------------------------------------
I simply modified the function 'f1(ang)' that you provided
-------------------------------------------------------
x^2+d*y*4+d^2*(-4)$
e1: rhs(first(solve(x^2+d*y*4+d^2*(-4),y)));
en1: 10$ /* set x = 10 */
f1(ang) := block([n, en2:5],
e2: subst([x=en1, d=en2],[first(diff(e1,x)), diff(e1,x)]),
%phi[1] : first(e2),
%phi[2] : second(e2),
ang : [(%phi[1]*d*(-2)),(d+((%phi[1])^(2)*d*(-1)))],
[(%phi[2]*d*(-2)),(d+((%phi[2])^(2)*d*(-1)))],
((%pi*1/2)+(atan((((%phi[1]+(%phi[2]*(-1))))^((-1))*(1+(%phi[2]*%phi[1]))))*
(-1))),
for i:1 thru n while ang # 0.178092938 do en2 : en2+i,
return (en2)); /*Should return en2:55. I do not
understand what's going on here. */
-------------------------------------------------------
to look like this so that it would output the value of the statement where I
thought 'ang' should be assigned.
In the process, I changed the initial value of en2 to 1, made the parameter
'ang' to be 'nIn', and initialized the value of 'n' to 'nIn' minus 1 when
'f1(nIn)' is invoked.
-------------------------------------------------------
x^2+d*y*4+d^2*(-4)$
e1: rhs(first(solve(x^2+d*y*4+d^2*(-4),y)));
en1: 10$ /* set x = 10 */
/*f1(ang) := block([n, en2:5], Use a different parameter name */
f1(nIn) := block([ang, n:nIn-1, en2:1], /*add initialization for n, and
modify en2 value*/
/*for i:1 thru n while ang # 0.178092938 do ( */
for i:0 thru n do (
e2:subst([x=en1, d=en2],[first(diff(e1,x)), diff(e1,x)]),
%phi[1] : first(e2),
%phi[2] : second(e2),
[(%phi[1]*d*(-2)),(d+((%phi[1])^(2)*d*(-1)))],
[(%phi[2]*d*(-2)),(d+((%phi[2])^(2)*d*(-1)))],
ang :
((%pi*1/2)+(atan((((%phi[1]+(%phi[2]*(-1))))^((-1))*(1+(%phi[2]*%phi[1]))))*
(-1))),
en2 : en2 + 1 /*Need variable increment here that can be less than
1.0*/
),
return( float(ang) )
);
-------------------------------------------------------
I added a few more explanatory notes this morning to illustrate:
-------------------------------------------------------
x^2+d*y*4+d^2*(-4)$
e1: rhs(first(solve(x^2+d*y*4+d^2*(-4),y)));
en1: 10$ /* set x = 10 */
/*f1(ang) := block([n, en2:5], Use a different parameter name */
/*nIn is just the number of iterations*/
f1(nIn) := block([ang, n:nIn-1, en2:1], /*add initialization for n, and
modify en2 val*/
/*for i:1 thru n while ang # 0.178092938 do ( */
for i:0 thru n do (
e2:subst([x=en1, d=en2],[first(diff(e1,x)), diff(e1,x)]),
%phi[1] : first(e2),
%phi[2] : second(e2),
/* The following two lines don't seem to be doing anything
[(%phi[1]*d*(-2)),(d+((%phi[1])^(2)*d*(-1)))],
[(%phi[2]*d*(-2)),(d+((%phi[2])^(2)*d*(-1)))], */
/*If this is the value you want, then 'ang' has to be assigned here*/
ang :
((%pi*1/2)+(atan((((%phi[1]+(%phi[2]*(-1))))^((-1))*(1+(%phi[2]*%phi[1]))))*
(-1))),
/*en2 is just acting as a counter that is incremented at each
iteration*/
en2 : en2 + 1 /*Need variable increment here that can be less than
1.0*/
),
return( float(ang) )
);-------------------------------------------------------
If indeed the value of 'ang' as it's shown in the modified 'f1(nIn)' is what
you want, then to get more accuracy would require the value of 'en2' to
increment at a rate less than 1.0 as you get closer to the value you desire.
I made no accommodations to supply a target value or to provide the means to
converge to one. That would require checking the value of 'ang' after each
assignment and taking steps to change the increment rate of 'en2' and also
to to accommodate overshooting the target value as you tried to converge to
the target.
When I invoked 'f1(56)' I just tried a few values to see if it was producing
the same output as the statements that were given external to those in
'f1(nIn)'.
I hope this helps,
Paul Bowyer
On 09/06/2010 09:01 PM, William Porter wrote:
Thank you Paul and Robert for your input. It is greatly appreciated.
I am too inexperienced with Maxima to carry it much farther than what Paul
has outlined. I have tried to use the find_root (<some expression>, en2, 10,
80); at the end of Paul's outline. Unfortunately I am not sure what to
insert in for <some expression>. Guessing at what expression to enter, I
have tried f1, ang, nIn, etc. but just guessing with no results.
On the last line f1(56); how did you know to insert the value 56? Is there
an expression that would generate the value?
Also on line en2 : en2 + 1), /*Need variable increment here that can be
less than 1.0*/. what would be an example?
x^2+d*y*4+d^2*(-4)$
e1: rhs(first(solve(x^2+d*y*4+d^2*(-4),y)));
en1: 10$ /* set x = 10 */
f1(nIn) := block([ang, n:nIn-1, en2:1],
for i:0 thru n do (
e2:subst([x=en1, d=en2],[first(diff(e1,x)), diff(e1,x)]),
%phi[1] : first(e2),
%phi[2] : second(e2),
[(%phi[1]*d*(-2)),(d+((%phi[1])^(2)*d*(-1)))],
[(%phi[2]*d*(-2)),(d+((%phi[2])^(2)*d*(-1)))],
ang :
((%pi*1/2)+(atan((((%phi[1]+(%phi[2]*(-1))))^((-1))*(1+(%phi[2]*%phi[1]))))*
(-1))),
en2 : en2 + 1), /*Need variable increment here that can
be less than 1.0*/
return( float(ang) ) );
f1(56); /* How do you know to enter the 56 value? Can the
expressions generate this value? */
William Porter
wporter at omegapar.com
__________ Information from ESET NOD32 Antivirus, version of virus signature
database 5429 (20100906) __________
The message was checked by ESET NOD32 Antivirus.
http://www.eset.com
__________ Information from ESET NOD32 Antivirus, version of virus signature
database 5432 (20100907) __________
The message was checked by ESET NOD32 Antivirus.
http://www.eset.com