Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9193035
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T21:04:00+00:00 2026-06-17T21:04:00+00:00

# Prototype of N-R for a system of two non-linear equations #evaluating functions of

  • 0
# Prototype of N-R for a system of two non-linear equations
#evaluating  functions of two variables
# f(x,y)=1.6 * x ** 2 + 3.6 * x * y - 7.8 * x - 2.6 * y + 5.2
# g(x,y)=0.9 * y ** 2 + 3.1 * x **2 - 6.2 * x + 6.2 * y

# x = 0.5
# y =0.4

from math import *

eq1 = raw_input('Enter the equation 1: ')
eq2 = raw_input('Enter the equation 2: ')
x0 = float(input('Enter x: '))
y0 = float(input('Enter y: '))

def f(x,y):
    return eval(eq1)

def g(x,y):
    return eval(eq2)

Ea_X = 1
x = x0
y = y0

for n in range(1, 8):

    a = (f(x + 1e-06, y) - f(x,y)) / 1e-06   #in this one start the trouble
    b = (f(x, y + 1e-06) - f(x,y)) / 1e-06
    c = 0 - f(x,y)
    d = (g(x + 1e-06, y) - g(x,y)) / 1e-06
    eE = (g(x, y + 1e-06) - g(x,y)) / 1e-06
    f = 0 - g(x,y)


    print "f(x, y)= ", eq1
    print "g(x, y)= ", eq2
    print """x   y """
    print x, y
    print """a   b   c   d   e   f """
    print a, b, c, d, e, f

    print """
    a * x + b * y = c
    d * x + e * y = f
    """

    print a," * x  +  ",b," * y  =  ",c
    print d," * x  +  ",eE," * y  =  ",f

    _Sy = (c - a * f / d) / (b - a * eE / d)
    _Sx = (f / d) - (eE / d) * _Sy

    Ea_X = (_Sx ** 2 + _Sy ** 2)**0.5


    x = x + _Sx
    y = y + _Sy

    print "Sx = ", _Sx
    print "Sy = ", _Sy

    print "x = ", x
    print "y = ", y

    print "|X_1 - X_0| = ", Ea_X

I’ve been testing the Newton-Rapson method for two non-linear equations,
the prototype code works but then I was thinking in making it more
useful, because the prototype is about the input of the 2 equations
and the first guesses, and it would be good to implement a for loop
instead of starting the process like 6 or 10 to resolve just one
of the so many equations that I’m working with

# Prototype of N-R for a system of two non-linear equations
# f(x,y)=1.6 * x ** 2 + 3.6 * x * y - 7.8 * x - 2.6 * y + 5.2
# g(x,y)=0.9 * y ** 2 + 3.1 * x **2 - 6.2 * x + 6.2 * y

# x = 0.5
# y =0.4


# evaluating  functions of two variables

from math import *


eq1 = raw_input('Enter the equation 1: ')
eq2 = raw_input('Enter the equation 2: ')
x0 = float(input('Enter x: '))
y0 = float(input('Enter y: '))

def f(x,y):
    return eval(eq1)

def g(x,y):
    return eval(eq2)

Ea_X = 1
x = x0
y = y0

a = (f(x + 1e-06, y) - f(x,y)) / 1e-06
b = (f(x, y + 1e-06) - f(x,y)) / 1e-06
c = 0 - f(x,y)
d = (g(x + 1e-06, y) - g(x,y)) / 1e-06
eE = (g(x, y + 1e-06) - g(x,y)) / 1e-06
f = 0 - g(x,y)


print "f(x, y)= ", eq1
print "g(x, y)= ", eq2
print """x   y """
print x, y
print """a   b   c   d   e   f """
print a, b, c, d, e, f

print """
a * x + b * y = c
d * x + e * y = f
"""

print a," * x  +  ",b," * y  =  ",c
print d," * x  +  ",eE," * y  =  ",f

_Sy = (c - a * f / d) / (b - a * eE / d)
_Sx = (f / d) - (eE / d) * _Sy

Ea_X = (_Sx ** 2 + _Sy ** 2)**0.5


x = x + _Sx
y = y + _Sy

print "Sx = ", _Sx
print "Sy = ", _Sy

print "x = ", x
print "y = ", y

print "|X_1 - X_0| = ", Ea_X
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T21:04:01+00:00Added an answer on June 17, 2026 at 9:04 pm

    In the line

    f = 0 - g(x,y)
    

    you assign a number to the name f. Since functions and other variables share a namespace in Python (a function is just a callable object, bound to any variable), this makes future iterations fail. Pick another name for the value you’re assigning in the above line.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using Prototype, I'm trying to extract a piece of text from the DOM -
I'm using python to prototype the algorithms of a computer vision system I'm creating.
I am (stuck) using Prototype 1.3.1 and I'm having a hard time moving from
I'm working on a prototype system which will act as a proof of concept
I need to prototype a very simple system which sends a request to a
I'm new to C#/Java and plan to prototype it for soft real-time system. If
I built a prototype system with some database queries. Since it was just a
I'm currently developing a registration system prototype. It's very simplistic and essentially is just
I'm trying to write a really simple prototype of a CMS system using ASP.Net
I am looking for a prototype or implementation for a queueing/scheduling system with dependencies

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.