Thread has been deleted
Last comment
PYTHON EXPERTS
rain | 
Norway RainNumber1 
I need help for a few things, the halving method and newtons method As an example lets say I get the equation x - 3 = 0 how do I solve that by using the halving method and how do I solve the same equation using the newtons method? I think I came to the answer 1, 6666 using the newtons method but I think it could be wrong, and I didnt manage how to do it with the halving method. Could someone try to do it using python and paste it in this thread. Thanks in advance
2021-04-08 12:35
Topics are hidden when running Sport mode.
And also if u have time: Equation set: f(x) = x2 + x-3 and g(x) = 2x2 - 2x-3 find the answer to that equation set when: g(x) = f(x)
2021-04-08 12:37
5 replies
X2? Do you mean x^2?
2021-04-08 17:48
4 replies
ye. Can u do that one in python?
2021-04-08 18:28
3 replies
It's a standard way of writing powers of.
2021-04-09 07:51
2 replies
I mean can u Solve the equation set at #1 in python. I am stuck.
2021-04-09 12:21
1 reply
Sorry I am a Java dev.
2021-04-09 13:03
print('Hello World')
2021-04-08 12:37
10 replies
I am not that big of a noob xd
2021-04-08 12:37
+1
2021-04-08 14:27
+1 works! +rep
2021-04-08 15:29
#70
 | 
Canada roylin
+1
2021-04-08 15:33
#99
 | 
Finland Cucumber))
+1
2021-04-08 16:30
+1 new einstein
2021-04-08 16:57
it works! thanks bro!
2021-04-08 18:49
+1
2021-04-08 19:26
+1
2021-04-09 08:04
+1
2021-04-09 14:03
anyone that can help?
2021-04-08 12:40
Imagine asking on hltv instead of stackoverflow
2021-04-08 12:42
3 replies
rather ask on hltv than stackshitflow
2021-04-08 12:54
tbf stackoverflow is hella toxic and full of even worse socially awkward individuals than HLTV
2021-04-08 16:34
1 reply
+1. Plus mods always change people's comments without their consent. Bullshit practice
2021-04-08 19:45
def newton(f,Df,x0,epsilon,max_iter): '''Approximate solution of f(x)=0 by Newton's method. Parameters ---------- f : function Function for which we are searching for a solution f(x)=0. Df : function Derivative of f(x). x0 : number Initial guess for a solution f(x)=0. epsilon : number Stopping criteria is abs(f(x)) < epsilon. max_iter : integer Maximum number of iterations of Newton's method. Returns ------- xn : number Implement Newton's method: compute the linear approximation of f(x) at xn and find x intercept by the formula x = xn - f(xn)/Df(xn) Continue until abs(f(xn)) < epsilon and return xn. If Df(xn) == 0, return None. If the number of iterations exceeds max_iter, then return None. Examples -------- >>> f = lambda x: x**2 - x - 1 >>> Df = lambda x: 2*x - 1 >>> newton(f,Df,1,1e-8,10) Found solution after 5 iterations. 1.618033988749989 ''' xn = x0 for n in range(0,max_iter): fxn = f(xn) if abs(fxn) < epsilon: print('Found solution after',n,'iterations.') return xn Dfxn = Df(xn) if Dfxn == 0: print('Zero derivative. No solution found.') return None xn = xn - fxn/Dfxn print('Exceeded maximum iterations. No solution found.') return None
2021-04-08 12:42
Have u tried using a calculator? :()
2021-04-08 12:42
x-3=0 x=3 Solved
2021-04-08 12:43
8 replies
yes but in python
2021-04-08 12:45
4 replies
x = 0 + 3
2021-04-08 13:00
Are you dumb? x-3=0 |+3 x=0+3 (0+3=3) x=3
2021-04-08 13:04
2 replies
'Are you dumb?' Bro he's just asking, everyone starts somewhere with coding.
2021-04-08 14:18
1 reply
I was baiting lmao
2021-04-08 16:13
genius xd
2021-04-08 18:54
1 reply
thanks
2021-04-08 19:03
#133
 | 
Russia mrPIVO
n1
2021-04-08 19:25
#9
 | 
Lithuania marusgg
I'm a python expert but this is math and i failed math few times in uni so noppers
2021-04-08 12:44
2 replies
rip
2021-04-08 12:52
Me too but i only know this equation with apples
2021-04-08 16:59
#13
 | 
Reunion Esquinox
send ur code
2021-04-08 12:54
i am a python expert in rust what do you need help with
2021-04-08 12:55
python is cringe c++ superior
2021-04-08 12:56
24 replies
50-year-old ex card programmer right there
2021-04-08 13:09
21 replies
nt python is really slow c++ better and best
2021-04-08 13:10
20 replies
#26
 | 
Lithuania marusgg
#23, expected from lithuanian also
2021-04-08 13:50
16 replies
nt pole living in vilnius
2021-04-08 16:02
15 replies
#78
 | 
Lithuania marusgg
mens mens mens imagine living in rural lithuania xD
2021-04-08 16:03
14 replies
i live in klaipeda and its fine 🤡
2021-04-08 16:04
13 replies
#82
 | 
Lithuania marusgg
yes, rural lithuania btw do you enjoy the smell all the time?
2021-04-08 16:13
12 replies
🤡🤡🤡🤡🤡🤡🤡🤡🤡🤡🤡🤡🤡🤡🤡🤡🤡🤡🤡🤡🤡🤡 what smell
2021-04-08 16:14
11 replies
#86
 | 
Lithuania marusgg
idk whenever i come to klaipeda theres this piss smell everywhere in the city u prob already used to it, np mens
2021-04-08 16:16
10 replies
there is piss smell in beaches in summer when everyone from vilnius comes🤡
2021-04-08 16:16
9 replies
#88
 | 
Lithuania marusgg
imagine going to klaipėda for the beaches ????????????????????
2021-04-08 16:17
8 replies
why else? horrible city
2021-04-08 16:30
7 replies
Palanga > Klaipeda idiota
2021-04-08 17:47
6 replies
no lol kaunas > klaipeda > palanga > vilnius
2021-04-08 17:51
5 replies
Kaunas??????????? Who goes to Kaunas for Beaches????
2021-04-08 17:53
4 replies
not talking about beaches just in general
2021-04-08 17:53
3 replies
in general? Vilnius > Palanga > Kaunas > Klaipeda
2021-04-08 17:54
2 replies
lol no
2021-04-08 17:55
1 reply
lol yes
2021-04-08 17:55
You can run c++ modules in python for stuff that has to be really fast.
2021-04-08 14:17
1 reply
don't tell them
2021-04-08 14:36
Run python on python using PyPy - that's fast bruh
2021-04-08 16:06
#93
 | 
Italy MulaManca
Imagine not using Java (but I like c++ as well)
2021-04-08 16:19
#136
 | 
Kazakhstan Massaget
you need speed? go deeper, use assembler then
2021-04-08 19:30
sorry bro going to start learn py this summer so can't help u rn:(
2021-04-08 12:56
I'm sorry but currently I'm learning java, will answer your question in a few months when I start python :D
2021-04-08 13:01
i can help. but have u tried answering it yourself? have u written a code?
2021-04-08 13:05
40 replies
yes I have written a code that can find the answer to any equation I think. I just have to derive the equation by hand. And I got the answer 3. Using the newtons method. But I dont know how to do it with the halving method. But I have no idea how to do this: Equation set: f(x) = x2 + x-3 and g(x) = 2x2 - 2x-3 find the answer to that equation set when: g(x) = f(x) could u help me with that last one there?
2021-04-08 13:28
39 replies
#30
 | 
Indonesia segopecel
you mean bisection method? i think its the easiest one out there, how come you're not understand let me see your newton method first, copy it in ideone.com/ and write the link here
2021-04-08 14:01
20 replies
thats java.. I am doing python
2021-04-08 14:07
19 replies
#34
 | 
Indonesia segopecel
you can change the language in bottom of the page, a dropdown menu. choose python or python 3
2021-04-08 14:07
18 replies
ideone.com/ZU9MIo I got the newton = 3 Is that correct? But I also need the time newtons method took to find it, So what number show be in an = ? I wrote an = 1.. but I dont think thats right I think I need to print another one with print ("Newtons time", tid, "seconds") or something
2021-04-08 14:10
17 replies
#39
 | 
Indonesia segopecel
cmon bruh, equation x-3=0 should have 3 as solution what is function fder do? edit:np i just understood
2021-04-08 14:20
15 replies
so was it right?
2021-04-08 14:24
14 replies
#57
 | 
Indonesia segopecel
sry, i was doing errand shouldn't you check whether f(a) equal zero or not first?
2021-04-08 15:06
13 replies
#58
 | 
Indonesia segopecel
or is it included in tolerance check? but why using loop inside function? shouldn't you use iterative function? wait, is this math class or programming class? if its math class should be okay
2021-04-08 15:09
12 replies
programming class
2021-04-08 15:17
11 replies
#63
 | 
Indonesia segopecel
if i do my function like this, will you understand? ideone.com/Y67E09 with maxiter and tolerance are global variable, defined outside of newton function so instead using loop, you call the function itself inside the newton function
2021-04-08 15:25
10 replies
I havent learned about maxiter and iter, so idk tbh
2021-04-08 15:26
9 replies
#66
 | 
Indonesia segopecel
maxiter is N in your code, iter is number of iteration done sry, iedited my reply, maybe you havent read my explanation
2021-04-08 15:28
8 replies
#68
 | 
Indonesia segopecel
is it better learn the math first before writing the code? have you learn to write fibbonaci or factorial function before?
2021-04-08 15:30
7 replies
idk but i sent in those codes on #62 first one is halving method, second one is newton are they good enough? or should I change something?
2021-04-08 15:33
#109
 | 
Poland aiken
His loop version is better, you should always try to replace recurrence with looping unless it's very trivial and deterministic. With recurrence and big maxiter you may build call stack to dangerous size. In some languages you can hit stack limit pretty fast. It's neither optimal nor safe.
2021-04-08 17:45
5 replies
#120
 | 
Indonesia segopecel
make sense. thank you. you are right i just cant imagine using numerical methods as loop exercise for programming class, because the way it is taught in math. so i made assumption(my bad) this should be done using recurrence. and i actually only code briefly in my numerical analysis class, in which the problems barely hit any limit
2021-04-08 18:02
4 replies
#122
 | 
Poland aiken
Yea, exactly. The recurrence solution is much closer to math theory behind it. That's why it's often being taught that way. I think (but I'm not sure because I'm still sleeping on functional languages) that languages like Erlang support recurrence in slightly different way underneath and recurrence may be preferred solution over there.
2021-04-08 18:22
2 replies
in functional languages like Erlang or Haskell (and I would guess modern imperative like Rust and such) the compiler optimises recursion using a technique called tail-call optimisation to prevent overflowing the call stack. Or just converts it to a loop.
2021-04-09 13:05
1 reply
#147
 | 
Poland aiken
Cool, thanks for confirmation.
2021-04-09 14:02
#124
 | 
Poland aiken
btw. I checked stack call size limits and in Python it's 1000 and in Java 7-10k calls by default.
2021-04-08 18:26
#55
 | 
Poland aiken
'an' is a first guess as I understand so it should work with any value, but you need to calculate first 'c' for it
2021-04-08 15:03
you need to write a code that first determines what kind of equation has been input and then solve it that way. so an equation that has a first term ax^2 is different than an equation which has first term ax^3 where a is any integer. you need to have if conditions in your code regarding that. i can pm you my discord if u want more help.
2021-04-08 14:35
17 replies
but I think I managed to do it using both methods now. The answer is 3 tho right?? Cuz I got 3 using both methods. Or 2,9999998 using the halving method but ye
2021-04-08 14:52
2 replies
are u trolling? because its obvious the answer is 3, even my 10 year old bro would know that
2021-04-08 15:03
1 reply
xdddd ye I know but what values should I use for a and b in the halving method? does it even matter?
2021-04-08 15:18
2021-04-08 15:20
13 replies
#71
 | 
Indonesia segopecel
maybe use b=4? are you in loop module right now? thus should be good enough
2021-04-08 15:38
12 replies
ok ty bro
2021-04-08 15:48
but what about this btw: I have to find the answer using any method I want: f(x) = x2 + x - 3 and g(x) = 2x2 - 2x - 3 Find the answer to the equation set above when: g(x) = f(x) can u do this one so i can see?
2021-04-08 15:52
10 replies
#75
 | 
Indonesia segopecel
make another function h(x)=g(x)-f(x) and find x that satisfy h(x)=0 like when you do f(x)=x-3=0 now do h(x)=0
2021-04-08 15:56
9 replies
differential equation. we assume f0 = 0 f' (x) = 5 + f(x) what is the answer to the one above. I got to: 0. 0.526...... 1.107...... 2.460........ 3.245......... 4.113............ 5.072......... 6.132...... 7.303.... correct?
2021-04-08 16:15
6 replies
#91
 | 
Indonesia segopecel
how?? if you do the math manually you will find the solution either 0 or 3 what method do you use, newton or halving?
2021-04-08 16:18
5 replies
2021-04-08 16:31
Its a new task btw... its not this one: f(x) = x2 + x - 3 and g(x) = 2x2 - 2x - 3 I am talking about this task: differential equation. we assume f0 = 0 f' (x) = 5 + f(x)
2021-04-08 16:32
3 replies
#104
 | 
Indonesia segopecel
and what is this question asked? f(1)?
2021-04-08 16:55
2 replies
I wrote the task here: ideone.com/m9xqb6 can u do that for me please?
2021-04-08 18:24
1 reply
#128
 | 
Indonesia segopecel
have you done with the #101 problem? if you could do that, this one is similar but with 2 function. basically list the value of K and I for every x between 0 and 850 then find highest I-K and i dont know how to plot data using python btw if you want to copy word(not code) better use pastebin.com/ (or similar services online)
2021-04-08 18:44
s
2021-04-08 16:32
s
2021-04-08 16:32
x - 3 = 0 answer is -x3 = JW washed up
2021-04-08 13:06
For your equation set f(x) = x2 + x-3 and g(x) = 2x2 - 2x-3: def fSolve (x): #solve equation f(x) where you decide on x fx = x*2 + x-3 gSolve return fx def gSolve(fx): #solve equation using f(x) gx = 2*fx*2 - 2*fx-3 return gx #print stuff if u wish print(f'g(1) = {gSolve(fSolve(1))}') #g(1) = -3 print(f'g(3) = {gSolve(fSolve(-3))}') #g(3) = -27 print(f'g(-1) = {gSolve(fSolve(-1))}') #g(-1) = -15 print(f'g(3) = {gSolve(fSolve(-3))}') #g(3) = -27 not the prettiest thing i wrote and if i understand correctly what u mean by halving method (10*15=5*30), that only works for multiplication
2021-04-08 13:10
2 replies
can u write it in ideone.com ? U can also do it with the newton method or other methods u choose. but yeah Task: f(x) = x^2 + x - 3 and g(x) = 2x^2 - 2x - 3 g(x) = f(x)
2021-04-08 18:33
1 reply
2021-04-08 19:34
You don't need to be an expert to know that x - 3 = 0 means it's 3 - 3 = 0 so 0 = 0 Bye
2021-04-08 13:56
1 reply
You expert!
2021-04-08 18:02
#29
 | 
Canada GGNORE33
There are many different pythons, but I think they are not poisoned at all? What you need for them, you wanna buy?
2021-04-08 13:58
stop being lazy. you'll get nowhere in life asking for people to do YOUR stuff
2021-04-08 14:04
2 replies
but I want examples... So I can use it later... How can I learn this without help..
2021-04-08 14:07
1 reply
so please come up with a more specific question. Asking for help is fine. But you need to ask good questions. Asking people to solve the problem for you and paste the solution so you can use is not good for you, nor for the person doing this, nor for your school, etc. this is cheating
2021-04-08 15:53
#36
 | 
Czech Republic Luck9nN
fuck, I came here assuming you would need help with your pet python
2021-04-08 14:10
#37
 | 
Iceland caverat
this isnt python overall, just math tho
2021-04-08 14:11
1 reply
#54
 | 
Brazil brasiI
no
2021-04-08 15:01
#38
 | 
Brazil Nero7
im a Python expert, but i dont see anything related to a Python here. The Pythonidae, commonly known as pythons, are a family of nonvenomous snakes found in Africa, Asia, and Australia. Among its members are some of the largest snakes in the world. WTF math has anything to do with it?
2021-04-08 14:16
#41
 | 
Finland orange_719
I literally just today had to code newtons method for solving the cubic root of a for a test in school this is the code I came up with and it works so just put your own function in it and it should work so lets say that the cubic root of a is x so that means that x*x*x=a so the function is x*x*x-a and I then derivated it manually a=input("the number from which you want the root from: ") c=int(a) x=1 d=10 g=0 #code runs until two numbers are closer than 0,000001 of each other while (int(d)<<1): q=(x-(x*x*x-c)/(3*(x*x))) #code doesn't like decimals and I'm too retarded to sort it d=(abs(q-x))*1000000 x=q g=g+1 print("iterations: "+str(g)) print(q) this only works for the cubic root of a number but you can put your own function in it if you know how
2021-04-08 14:18
How about you simply google halving method and newtons method in Python, and apply whatever you find to your problem? It's better idea than asking people on HLTV
2021-04-08 14:20
import math def halving_method(a, b, f, tolerance): c = (a + b) / 2 f_c = f(c) if abs(f_c) < tolerance: return c else: if math.copysign(1, f_c) == math.copysign(1, f(a)): return halving_method(c, b, f, tolerance) else: return halving_method(a, c, f, tolerance) a = -10 b = 10 tolerance = 0.1 f = lambda x: x - 3 print(f"The root of the function f is {halving_method(a, b, f, tolerance)}")
2021-04-08 14:28
2 replies
Indentation broke, so here's an image of the code: imgur.com/a/p2E6u7i You can adjust "a" and "b" as starting points, you can set "f" as the function you want and you can set the "tolerance" of how close to the real root you want the algorithm to stop looking. Also you have to make sure that the root of the function is between "a" and "b", or else the function won't converge
2021-04-08 14:34
the answe comes up as none? but the answer should be 3 tho?
2021-04-08 16:38
Use stack overflow not the HLTV forum....
2021-04-08 14:35
Imagine not using matlab to solve math equations
2021-04-08 14:57
pastebin.ubuntu.com/p/q4g5wnqPZ6/ Here is the code i wrote when i studied this. You need to input the interval [a,b] where the solution is and the error epsilon. I use the array to calculate the error.
2021-04-08 15:09
#64
 | 
Germany Droidd
3 - 3 = 0 free x = 3
2021-04-08 15:26
easy import math def solve(a , b , c): d = math.sqrt(b**2 - (4 * a * c)) x1 = (-b - d) / (2 * a) x2 = (-b + d) / (2 * a) return x1,x2 k = int(input("You Choose equation type press 1 or 2 \n 1-) x - a = 0 \n 2-) ax^2 + bx + c = 0")) if k == 1: a = int(input("enter the number a")) print("x1 = %s" %(-a)) elif k==2: a = int(input("enter the a : ")) b = int(input("enter the b : ")) c = int(input("enter the c : ")) x1 , x2 = solve(a , b , c) print("x1 ->" , x1) print("x2 ->" , x2) else: print("enter 1 or 2")
2021-04-08 16:07
Stackoverflow mate, its your best option :)
2021-04-08 16:17
2021-04-08 16:17
2 replies
this is the way to go if learning/practicing isn't your purpose and you're only interesting and use it as a tool.
2021-04-08 16:19
1 reply
#105
 | 
Portugal antCB
exactly. the way he asked for help, he is probably also learning problem solving (or trying to). I was always mad at programming teachers when they didn't let us use libs or functions already present in any given language to obtain the same outcome... but years later I completely understand why.
2021-04-08 16:56
cobra mens))))))))))))))
2021-04-08 16:21
Sorry dude, I'm not doing your homework. If you are unable to figure that out on your own, I dont think ICT is for you
2021-04-08 16:24
#108
 | 
Finland Goble81
Nice try. Do your homeworks properly. The logic of "bisection" is quite easy to implement in Python (or in any language), but a bit too much to be placed here just in few code lines. It is more than two-three code lines if you do the code from scratch instead of using pre-existing libraries. And how to use a pre-existing library solution is not probably what your teacher is asking for.
2021-04-08 17:14
#118
 | 
United States 7hai
this is not really a python question ^^
2021-04-08 17:55
X = 3 ???
2021-04-08 18:27
I can help but I guess the problem is already solved. Don't use python. Almost everything has a built in library and you don't actually get to know the concepts in depth
2021-04-08 18:54
1 reply
People who want to learn things in depth will do so no matter the language. Nothing stops someone from looking at the source of a library they're using.
2021-04-09 13:07
#138
 | 
Poland aiken
I improved your code and I made it more transparent what's actually happening. I also added another example of a function as f(x) = x - 3 is resolvable by newton method in 1 iteration. Enjoy. ideone.com/Iwofkg
2021-04-08 19:41
I think you firstly need to add math library, import matplotlib.pyplot as pl (I guess this is the right one) just type some equation or give x some numbers and it automatically solves it unless it is topology
2021-04-09 12:27
Login or register to add your comment to the discussion.