calculus

Haskell - How to write (.) f f = (\x -> f (f x))

*爱你&永不变心* 提交于 2019-12-08 02:41:23
问题 I need to write on a module to be run on GHCi, with a function composition to the same function. This (The classic fog(x) = f(g(x)) ) runs: (.) f g = (\x -> f (g x)). The problem appears when I try to write it like this (.) f f = (\x -> f (f x)). (fof(x) = f(f(x))) GHCi says: "Conflicting definitions for `f' Bound at: Lab1.hs:27:9 Lab1.hs:27:12" Line 27:9 appear on the first time f and line 27:12 appear f again. Why doesn't Haskell understand (.) f f = (\x -> f (f x)) ? 回答1: In Haskell,

Haskell - How to write (.) f f = (\\x -> f (f x))

笑着哭i 提交于 2019-12-06 10:45:32
I need to write on a module to be run on GHCi, with a function composition to the same function. This (The classic fog(x) = f(g(x)) ) runs: (.) f g = (\x -> f (g x)). The problem appears when I try to write it like this (.) f f = (\x -> f (f x)). (fof(x) = f(f(x))) GHCi says: "Conflicting definitions for `f' Bound at: Lab1.hs:27:9 Lab1.hs:27:12" Line 27:9 appear on the first time f and line 27:12 appear f again. Why doesn't Haskell understand (.) f f = (\x -> f (f x)) ? Will Ness In Haskell, arguments to a function must have unique names. Using the same name for another argument is not allowed

Calculating APR using Reg Z Appendix J

*爱你&永不变心* 提交于 2019-12-06 04:49:47
问题 OK. I'm brand new to this site so "Hello All"! Well I've been wrestling with a difficult problem for the last week and I would appreciate any help you can give me. I know there are many formulas out there to calculate APR but I've tested many formulas and they do not handle Odd-Days properly for closed-end (consumer loans). The government has attempted to give us mere mortals some help with this by publishing an Appendix J to their truth-in-lending act. It can be found here: https://www.fdic

Calculating APR using Reg Z Appendix J

回眸只為那壹抹淺笑 提交于 2019-12-04 11:15:01
OK. I'm brand new to this site so "Hello All"! Well I've been wrestling with a difficult problem for the last week and I would appreciate any help you can give me. I know there are many formulas out there to calculate APR but I've tested many formulas and they do not handle Odd-Days properly for closed-end (consumer loans). The government has attempted to give us mere mortals some help with this by publishing an Appendix J to their truth-in-lending act. It can be found here: https://www.fdic.gov/regulations/laws/rules/6500-3550.html If you're brave (!!), you can see the formulas they provide

Finding the optimal 3D box sizes for a group of 3D rectangular items

你离开我真会死。 提交于 2019-12-03 16:17:14
When I say box I am talking about shipping boxes. I have a number of random sized, small items that I need to pack into as few boxes as possible. I need to know what box sizes are optimal. All items are rectangular prisms . It's easy to exclude a box size for an item which is too large to fit. I know the box sizes (they are the available box sizes which I have in-stock) Items can be positioned horizontally or vertically, not diagonal. As many boxes as required can be used. The goal is to use as few boxes as possible. Multiple box sizes may be used to optimally fit the varying-sized items. What

calculating the Gradient and the Hessian in R

混江龙づ霸主 提交于 2019-12-03 08:55:49
As you know, the Gradient of a function is the following vector: and the Hessian is the following matrix: Now, I wonder, is there any way to calculate these in R for a user defined function at a given point? First, I've found a package named numDeriv , which seems to have the necessary functions grad and hessian but now I can't get the correct results... Thus, here's my workflow: Let's say that we are given the function f(x,y) = x^2 * x^3, and we need to calculate the Gradient and the Hessian at the point (x=1, y=2). That's been said, I define this function within R: dummy <- function(x,y) {

harmonic series with x86-64 assembly

大兔子大兔子 提交于 2019-12-02 16:29:00
问题 Trying to compute a harmonic series. Right now I'm entering the number I want the addition to go up to. When I enter a small number like 1.2, the program just stops, doesn't crash, it seems to be doing calculations. BUt it never finishes the program here is my code denominator: xor r14,r14 ;zero out r14 register add r14, 2 ;start counter at 2 fld1 ;load 1 into st0 fxch st2 denomLoop: fld1 mov [divisor], r14 ;put 1 into st0 fidiv dword [divisor] ;divide st0 by r14 inc r14 ;increment r14 fst

Operations with arrays in Matlab

若如初见. 提交于 2019-12-02 11:01:15
问题 I have this 2-dimensional array x=[62,29,64; 63,31,62; 65,29,60; 63,29,62; 63,31,62;]; 1st element in each column is R, 2nd is G, 3rd is B from the formula below. I would like a function to compute the following operation: So far, my function definition looks like this: function[distance]=RGB_dist(x,y) distance=sqrt(sum(((x-y)*[3;4;2]).^2,2)); end Tested with the matrix above, disp(RGB_dist(x,x)) outputs only zeroes. That must happen because he is calculating the distance between same vectors

Operations with arrays in Matlab

廉价感情. 提交于 2019-12-02 03:46:13
I have this 2-dimensional array x=[62,29,64; 63,31,62; 65,29,60; 63,29,62; 63,31,62;]; 1st element in each column is R, 2nd is G, 3rd is B from the formula below. I would like a function to compute the following operation: So far, my function definition looks like this: function[distance]=RGB_dist(x,y) distance=sqrt(sum(((x-y)*[3;4;2]).^2,2)); end Tested with the matrix above, disp(RGB_dist(x,x)) outputs only zeroes. That must happen because he is calculating the distance between same vectors. How do I do to calculate the distance between any two vector(lines) from my matrix. Any help would be

scipy.integrate.quad precision on big numbers

你离开我真会死。 提交于 2019-12-01 23:33:20
I try to compute such an integral (actually cdf of exponential distribution with its pdf) via scipy.integrate.quad() : import numpy as np from scipy.integrate import quad def g(x): return .5 * np.exp(-.5 * x) print quad(g, a=0., b=np.inf) print quad(g, a=0., b=10**6) print quad(g, a=0., b=10**5) print quad(g, a=0., b=10**4) And the result is as follows: (1.0, 3.5807346295637055e-11) (0.0, 0.0) (3.881683817604194e-22, 7.717972744764185e-22) (1.0, 1.6059202674761255e-14) All the attempts to use a big upper integration limit yield an incorrect answer though the usage of np.inf solves the problem.