You are on page 1of 3

import numpy as np

import openpyxl

import os

i=0

dt = 0.05

T=6

N = int(T / dt)

A = np.array([[-1/20, 0, 0, 0, 120/20, 0, -120/20],

[0, -1/20, 0, 0, 0, 120/20, 120/20],

[-1/(2.4*0.08), 0, -1/0.08, 0, 0, 0, 0],

[0, -1/(2.4*0.08), 0, -1/0.08, 0, 0, 0],

[0, 0, 1/0.3, 0, -1/0.3, 0, 0],

[0, 0, 0, 1/0.3, 0, -1/0.3, 0],

[0.444, -0.444, 0, 0, 0, 0, 0]])

B = np.array([[-6, 0],

[0, -6],

[0, 0],

[0, 0],

[0, 0],

[0, 0],

[0, 0]])

x=np.array([0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0])


p = np.array([[0.01],

[0]])

excel_file_name = 'C:\\Users\\Hrithik\\Desktop\\a18.xlsx'

workbook = openpyxl.load_workbook(excel_file_name)

sheet = workbook.active

new_x = np.zeros_like(x)

while i<N:

if i!=0:

if i%15==0:

sheet.cell(row=i + 2, column=1, value=0.5)

sheet.cell(row=i + 2, column=2, value=0.5)

sheet.cell(row=i + 2, column=3, value=0.5)

j=j+1

print(j)

x[0] = sheet.cell(row=i + 2, column=1).value

x[1] = sheet.cell(row=i + 2, column=2).value

x[6] = sheet.cell(row=i + 2, column=3).value

for j in range(len(x)):

new_x[j] = x[j] + dt * (np.dot(A[j, :], x) + np.dot(B[j, :], p))[0]

x = new_x
print(x)

print(i)

sheet.cell(row=i + 3, column=1, value=x[0])

sheet.cell(row=i + 3, column=2, value=x[1])

sheet.cell(row=i + 3, column=3, value=x[6])

workbook.save(excel_file_name)

workbook.close()

i=i+1

You might also like