Posts

Showing posts with the label math

Getting Mathematical Errors Trying to calculate base price of gas

Getting Mathematical Errors Trying to calculate base price of gas I am trying to solve a problem that requires me to write code to find the base price of a gallon of gas. I am provided with the cost of a gallon of gas, the amount of federal and state tax, and the percent for sales tax. I've tried formatting the equation a couple different ways and the math is always wrong. This is the closest I've gotten (the output is $3.289 which is only .073 cents off, which when I do the calculations by hand happens to be the amount of sales tax so it is as if it is ignoring the end of the equation completely). Could I please get some assistance? I've included the entire problem I was given below. double pumpPrice=3.89, fedTax=.184, stateTax=.417, salesTax=2.25; double basePrice, totalTax, percentTax, profit_bigOil ; basePrice = pumpPrice-fedTax-stateTax-((salesTax*basePrice)/100) ; cout <<"The base price for a gallon of gas is $" <<basePrice << endl; Create ...

How do I compute derivative using Numpy?

How do I compute derivative using Numpy? How do I calculate the derivative of a function, for example y = x 2 +1 using numpy ? numpy Let's say, I want the value of derivative at x = 5... You need to use Sympy: sympy.org/en/index.html Numpy is a numeric computation library for Python – prrao Mar 26 '12 at 16:55 Alternatively, do you want a method for estimating the numerical value of the derivative? For this you can use a finite difference method, but bear in mind they tend to be horribly noisy. – Henry Gomersall Mar 26 '12 at 17:11 7 Answers 7 You have four options Finite differences require no ex...

How to rotate shape?

Image
How to rotate shape? What I've got so far: I'm able to draw shapes into a canvas using some simple syntax: let shape = "10n10" // example shapeSyntax (*) shapeSyntax: "1" == "colored area" "0" == "blank area" "n" == "new line" * So creating a simple line (width = 4, height = 1) is possible using the syntax "1111" * Creating a square (width = 2, height = 2) is possible using the syntax "11n11" (n stands for new line) * Creating a stair -shape would be possible using the syntax "001n011n111" This is working really good so far. So I've added the code so you can have a look at your own: What I'd like to get: I'd like to develop a function rotate(degree) that is able to rotate the syntax ( not just the canvas element or something else!!! ) of any shape around [90, 180, 270] degrees. rotate(degree) [90, 180, 270] So rotating a line with synta...