15,119,786 members
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])

```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)

Top Experts
Last 24hrsThis month
 OriginalGriff 230 Richard Deeming 135 k5054 105 Thomas Barbare 40 Rick York 35
 OriginalGriff 450 Richard Deeming 225 CHill60 145 k5054 105 Richard MacCutchan 90

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