Web Images Videos Maps News Shopping Gmail more »
Recently Visited Groups | Help | Sign in
Google Groups Home
Negative numbers and non-integer exponents
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  3 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Shem  
View profile  
 More options Feb 19, 5:12 pm
From: Shem <ssm.lauchapdela...@gmail.com>
Date: Thu, 19 Feb 2009 14:12:42 -0800 (PST)
Local: Thurs, Feb 19 2009 5:12 pm
Subject: Negative numbers and non-integer exponents
I am trying to plot half a parabola as a boundary however part of the
equation includes the term
(R - (Q^3 + R^2)^(1/2))^(1/3)

I tried

test = (-27)**(1/3)
.
.
.
printf("%d\n", $test)

and 0 is returned. If I remove the negative a 3 is returned.
What function can I use so that it would return the correct value? I
know C++ has the same problem with the pow function.

Thanks


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
michael  
View profile  
 More options Feb 19, 5:43 pm
From: "michael" <mertrid...@earthlink.net>
Date: Thu, 19 Feb 2009 14:43:40 -0800
Local: Thurs, Feb 19 2009 5:43 pm
Subject: Re: Negative numbers and non-integer exponents
you should do the calculations in the complex domain. if 27 is a complex
number declared by say numb=27 and numb is complex then it will give an
answer but the answer is complex


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
James Quirk  
View profile  
 More options Feb 19, 6:29 pm
From: James Quirk <j...@galcit.caltech.edu>
Date: Thu, 19 Feb 2009 15:29:41 -0800 (PST)
Local: Thurs, Feb 19 2009 6:29 pm
Subject: Re: Negative numbers and non-integer exponents

Michael is quite right that the cube root of a negative number
involves complex numbers. However, that is not the solution
to your problem. First off, the script fragment:

   test = (-27)**(1/3)
   printf("%d\n", $test)

is invalid, for AMRITA will try to run a procedure named "test."

The keyword "set" is used to assign to a string token.
But if you'd written:

   set test = (-27)**(1/3)
   printf("%d\n", $test)

you would actually have run:

   printf("%d\n", (-27)**(1/3))

as a plain set assigns a string. To force an evaluation of the
RHS you would need to use:

   set test #= (-27)**(1/3)
   printf("%d\n", $test)

For details, see:

   amrhelp set

Now to return to your question, the following draws
a half-parabola, in red, on the computational domain:

plugin amr_sol
EulerEquations
def Domain
   patch <1,1,100,100>
end def

postscript on
plotfile ps/tmp.ps
autoscale

set xo = 20
set a  = 5

p ::= sqrt(4*$a*(X[]-$xo))
r ::= Y[]<p[] ? 1 : -1
g ::= Y[]<p[] ? 0 : -1
b ::= Y[]<p[] ? 0 : -1

plot image rgb<r[],g[],b[]>
plot domain

It takes advantage of the fact that the plot image operator
treats a negative component as a transparent colour. The
downside of the above is that the parabola will be drawn
stepped. If that's a problem you can use the polygon
operator to draw a smooth parabola. For details, see:

  amrhelp polygon

or you can use the stroke facility:

  amrhelp stroke

In any event, you should recast your parabola in parametric
form thereby doing away with the need to take roots.

James


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2009 Google