#๐Ÿ”’ calculus

14 messages ยท Page 1 of 1 (latest)

ruby mantle
#

making code to turn integrals into reiman sum, and output the actual summation. i have teh baseline working, but i cant figure out hw to output the summation. the idea is to print a latex or plaintext summation.

import math
def summation(start, end, function):
    return sum(function(index) for index in range(start, end + 1))

def integral_to_reimann(a, b, f, n):
    return summation(0, n - 1, lambda i: f(a + i * ((b - a) / n)) * ((b - a) / n))

# Example usage
def f(x):
    return math.sqrt(1-x**2)

# Calculate the integral of f(x) from 0 to 1 with 1000 intervals
result = integral_to_reimann(-1, 1, f, 10000)
print(2*result)
wooden crownBOT
#

@ruby mantle

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

ruby mantle
#

cameron wb

bold root
#

Your summation is just a numeric value. What kind of latex stuff did you have in mind

ruby mantle
#

this is what i want it to be able to output

#

so like latex code with do that

bold root
ruby mantle
#

is it built in

#

nvm

bold root
#

You need to install sympy. Then you can, I gather, use its LatexPrinter to output latex.

wooden crownBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.