Python Forum
Solving an equation by brute force within a range
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Solving an equation by brute force within a range
#2
There seems to be quite a few problems with your code.
1. You aren't using indentations correctly
2. you are using sqrt for applying square root, but that is a function from the math library. I recommend using (x**0.5), it is
the same as square root.
3. The range function of python does not allow float values, as you are trying to apply.
4. For calling a function inside a print statement, use the format < print(function_name(x,y)) >

Below is a solution for the printing the values from 0,10 :

def eq(x, y):
    i = (x**2 + y**2)**0.5
    return i

for i in range (0, 10):
    print(eq(i,i))
for the values in the range you specified, I recommend using numpy, as it has a range function that supports float values :
import numpy as np

def eq(x, y):
    i = (x**2 + y**2)**0.5
    return i

eps = 0.001
delta = eps / 2
r = np.arange(0,10,delta)

for i in r:
    print(eq(i,i)) 
please take a look at some tutorials, if you are very confused.
Hopefully this helps
alexfrol86 likes this post
Reply


Messages In This Thread
RE: Solving an equation by brute force within a range - by kabeer_m - Mar-17-2022, 07:03 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
Question written RK solving same equation with different graphs acbshinn 1 448 Feb-09-2024, 12:33 PM
Last Post: Gribouillis
  Need an alternative to brute force optimization loop jmbonni 5 1,289 Dec-07-2023, 12:28 PM
Last Post: RockBlok
  force a program to exit ? Armandito 3 2,620 May-12-2022, 04:03 PM
Last Post: Gribouillis
  Solving equation equal to zero: How to resolve the syntax error? alexfrol86 3 2,044 Feb-21-2022, 08:58 AM
Last Post: deanhystad
  matplotlib x axis range goes over the set range Pedroski55 5 3,293 Nov-21-2021, 08:40 AM
Last Post: paul18fr
  Solving for zeros of an equation! fmitchell17 0 1,866 Apr-05-2021, 07:49 PM
Last Post: fmitchell17
  How to use scipy.optimization.brute for multivariable function Shiladitya 9 6,385 Oct-28-2020, 10:40 PM
Last Post: scidam
  best way to force an exception Skaperen 2 2,108 Oct-21-2020, 05:59 AM
Last Post: Gribouillis
  I need advise with developing a brute forcing script fatjuicypython 11 5,239 Aug-21-2020, 09:20 PM
Last Post: Marbelous
  How to Solving non-linear equation using scipy.optimize fsolve with variable list djhak 3 4,642 Jun-10-2020, 04:12 PM
Last Post: Gribouillis

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020