Area Under Curves and Volume of Revolving a Curve Discussions | Functional Programming | HackerRank
We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
A better way would be if the integral function received the function that it is supposed to integrate. Then the integral function would work with any function.
This is my integral function:
-- integral of any arbitrary function integralflr=sum[(fx)*dx|x<-[l,l+dx..r]]wheredx=0.001
The order of the parameters is meant to support currying. For example, lets say I want a function that is the integral of x^2:
-- this creates a function that is the integral of x ** 2, f=integral(**2)-- evaluate it like this:test=f1.04.0
Then you can use it to solve the problem like this:
-- Evaluates a polynomy. The parameters are ordered for curryingpoly::[Double]->[Double]->Double->Doublepolyabx=sum[ac*(x**bc)|(ac,bc)<-zipab]-- creates a function that is the rotation of an arbitrary-- function around the x axis.rotatefx=y*y*piwherey=fxareaablr=integral(polyab)lrvolumeablr=integral(rotate(polyab))lr
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Area Under Curves and Volume of Revolving a Curve
You are viewing a single comment's thread. Return to all comments →
A better way would be if the integral function received the function that it is supposed to integrate. Then the integral function would work with any function.
This is my integral function:
The order of the parameters is meant to support currying. For example, lets say I want a function that is the integral of x^2:
Then you can use it to solve the problem like this: