Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re^2: Regarding the polynomial evaluation. Stuck at one part. please helpppp!!

by freekngeek (Acolyte)
on Jan 22, 2013 at 14:43 UTC ( #1014681=note: print w/ replies, xml ) Need Help??


in reply to Re: Regarding the polynomial evaluation. Stuck at one part. please helpppp!!
in thread Calculating polynomials and pushing them into an array. Stuck at one part. please helpppp!!

You mean the input for the subroutine ? right ?

$$lvlhash{$level}{'POLY_BASED_EM_DC'}{'EM_POLY'}{11} = -0.137 + (0.004 +79 / (W/0.9)) + (2.5593 * (W/0.9 ) $$refhash{$level}{'MINDESIGNWIDTH'} = 0.045
when I print this :
print ("$$lvlhash{$level}{'POLY_BASED_EM_DC'}{'EM_POLY'}{11},$$refhash +{$level}{'MINDESIGNWIDTH'},0 \n");
I get this output on the terminal:
-0.137 + (0.00479 / (W/0.9)) + (2.5593 * (W/0.9 ) ,0.045,0
which means there's no problem in reading the values, but somehow it's not giving me what I really want to see :D


Comment on Re^2: Regarding the polynomial evaluation. Stuck at one part. please helpppp!!
Select or Download Code
Re^3: Regarding the polynomial evaluation. Stuck at one part. please helpppp!!
by Anonymous Monk on Jan 22, 2013 at 14:59 UTC

    You mean the input for the subroutine ? right ?

    Is that what you need help with?

    #!/usr/bin/perl -- use strict; use warnings; use Carp::Always; my $curWidth = my $curLength = 1; my $blah = q{-0.137 + (0.00479 / (W/0.9)) + (2.5593 * (W/0.9 ) ,0.045 +,0 }; print EvalPolynominal( $blah ); sub EvalPolynominal { #first parameter gives the polynominal string #second parameter gives the min-des width #third parameter gives the short-line length my $polynominal = shift; my $curWidth = shift; my $curLength = shift; $polynominal =~ s/W/$curWidth/g ;#replace W with current value of +min width $polynominal =~ s/L/$curLength/g ;#replace L with current value of + min Length return eval ($polynominal); } __END__ Use of uninitialized value $curWidth in substitution (s///) at blah li +ne 18. main::EvalPolynominal('-0.137 + (0.00479 / (W/0.9)) + (2.5593 * (W +/0.9 ) ,0.045,0 ') called at blah line 6 Having no space between pattern and following word is deprecated at (e +val 1) line 1. eval '-0.137 + (0.00479 / (/0.9)) + (2.5593 * (/0.9 ) ,0.045,0 ;' called at blah line 20 main::EvalPolynominal('-0.137 + (0.00479 / (W/0.9)) + (2.5593 * (W +/0.9 ) ,0.045,0 ') called at blah line 6

    eval is for perl code, not math

    build a calculator with marpa dsl or use Math::GSL::Poly but don't use eval

      more clearer , still avoid string-eval
      #!/usr/bin/perl -- use strict; use warnings; my $blah = q{-0.137 + (0.00479 / (W/0.9)) + (2.5593 * (W/0.9 ) ,0.045 +,0 }; print EvalPolynominal( $blah, 1,1 ); sub EvalPolynominal { #first parameter gives the polynominal string #second parameter gives the min-des width #third parameter gives the short-line length my $polynominal = shift; my $curWidth = shift; my $curLength = shift; $polynominal =~ s/W/$curWidth/g ;#replace W with current value of +min width $polynominal =~ s/L/$curLength/g ;#replace L with current value of + min Length local $@; my $ret = eval $polynominal; warn "Trying:\n\t$polynominal\nbut got: $@\n" if $@; return $ret; } __END__ $ perl -we " -0.137 + (0.00479 / (1/0.9)) + (2.5593 * (1/0.9 ) ,0.045 +,0 " syntax error at -e line 1, at EOF Execution of -e aborted due to compilation errors. $ perl blah Trying: -0.137 + (0.00479 / (1/0.9)) + (2.5593 * (1/0.9 ) ,0.045,0 but got: syntax error at (eval 1) line 2, at EOF Use of uninitialized value in print at blah line 4. $ perl -we " -0.137 + (0.00479 / (1/0.9)) + (2.5593 * (1/0.9 ) ,0.045 +,0 " syntax error at -e line 1, at EOF Execution of -e aborted due to compilation errors.

      Thanks for your reply. Yes, that's exactly what I need to solve. when I am running my script it's giving me these errors

      Use of uninitialized value $polynominal in substitution (s///) at /hom +e/vtyagi/perl/EMcheck1/pkg_EMIRcheck/EMIRcheck_tools.pm line 32. Use of uninitialized value $polynominal in substitution (s///) at /hom +e/vtyagi/perl/EMcheck1/pkg_EMIRcheck/EMIRcheck_tools.pm line 33. Use of uninitialized value $polynominal in eval "string" at /home/vtya +gi/perl/EMcheck1/pkg_EMIRcheck/EMIRcheck_tools.pm line 34.
      About eval, I have used eval for my last few scripts and it worked very smooth and it's also giving me outputs for the rest of the equations. May be next time i'll keep your advice in my mind and use Math::GSL::Poly. Do you think it could be the problem with format of that particular equation, I mean all the equation have been generated with same format, then what's the problem with this one.

        Do you think it could be the problem with format of that particular equation, I mean all the equation have been generated with same format, then what's the problem with this one.

        Hmm, perl seems to tell you that its a problem with that (syntax error)

        I wouldn't waste my time with string eval

Re^3: Regarding the polynomial evaluation. Stuck at one part. please helpppp!!
by tmharish (Friar) on Jan 22, 2013 at 15:09 UTC

    You are missing a bracket:

    -0.137 + (0.00479 / (W/0.9)) + (2.5593 * (W/0.9 ) ,0.045,0 -0.137 + (0.00479 / (W/0.9)) + (2.5593 * (W/0.9 ) <---- HERE ,0.045,0

    I still dont understand how this works - but it does!

    Update: Including testing code that ( I am not sure how ) works!

    use strict ; use warnings ; sub EvalPolynominal{ #first parameter gives the polynominal string #second parameter gives the min-des width #third parameter gives the short-line length my $polynominal=shift; my $curWidth=shift; my $curLength=shift; $polynominal =~ s/W/$curWidth/g ;#replace W with current value of ++min width $polynominal =~ s/L/$curLength/g ;#replace L with current value of ++ min Length my $result ; eval( $result = $polynominal ) ; # print "$result\n"; -- PRINTS THE STRING return eval ($polynominal); # Returns '0.086765' - WHY? } my $one = EvalPolynominal( '-0.137 + (0.00479 / (W/0.9)) + (2.5593 * ( +W/0.9 ))' ,0.045,0 ); print "$one\n";

      Thanks a lot man, It worked. So stupid of me, couldn't see that thing. I was missing a bracket. Your code worked because of the 2 brackets at the end of the equation and I was missing that one. It happened when I parsed the text into the array and I did something wrong. Thanks again

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1014681]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (5)
As of 2014-09-21 16:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (172 votes), past polls