summaryrefslogtreecommitdiff
path: root/tutorials/module_3/newton-raphson_nonlinear_systemspy
blob: 55a6cf15dfb14eac03bd7f6cbaaa54ad01c1b0e4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Sat Sep 27 15:31:11 2025

@author: christian
"""

u = lambda x, y: x**2 + x*y - 10
v = lambda x, y: y + 3*x*y**2 - 57

# Initial guesses
x_0 = 1.5
y_0 = 3.5

# Evaluate partial derivatives at initial guesses
dudx = 2*x_0+y_0
dudy = x_0

dvdx = 6*x_0*y_0
dvdy = 1 + 6*x_0*y_0

# Find determinant
det = dudx * dvdy - dudy * dvdx

# Values of functions valuated at initial guess
u_0 = u(x_0,y_0)
v_0 = v(x_0,y_0)

# Substitute into newton-raphson equation
x_1 = x_0 - (u_0*dvdy-v_0*dudy) / det
y_1 = y_0 - (v_0*dudx-v_0*dvdx) / det

print(x_1)
print(y_1)