Click here to Skip to main content
15,896,063 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am writing a python code for explicit Euler's method, where I got stuck with a particular step. How can I find the difference between two consecutive matrices (2x1)? The algorithm states if I can reach the difference to 0.005, then I can stop iterating the values for the variables (Euler's method to solve two dependent differential equation).

The problem is in using the while loop.

What I have tried:

import array as arr from array import * import numpy as np

#storing the T (tau) value:

T= arr.array('d', [0.18,0.16,0.14,0.12,0.10,0.08,0.06,0.04,0.02,0.001]) #time step

I= [[1, 0], [0, 1]]

A= [[-1, 10], [1, -10]]

w0= [[0.2], [0.8]] w1= [[0.0], [0.0]]

D= np.subtract(w0, w1) s=0;

for i in range(0, 1): 
    B =np.multiply(A, T[i]) 
    C= np.add(I, B)

while(D[0][0]>=abs(0.005) and D[1][0]>=abs(0.005)): #to specify the cutoff value
    D= np.subtract(w0, w1)
    w1= np.matmul(C, w0)
    w0=w1
    s=s+1; #to trace the number of iterations
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900