Jul 10

Computational Math Project

Information Comments Off on Computational Math Project

The heat conduction equation in a rod

For our final project, we were given a topic to look for a change of temperature on a stick within the stipulated time. For example, if a 100cm stick has a temperature of 100 ° C it will be cooled for 10 seconds. The purpose of this project is to find the temperature change every thousandth of a second for 10 seconds. So first, we will use numpy and matplotlib to calculate and search for results from this research. This can be done by:

import numpy as np;
import matplotlib.pyplot as plt
Import the following numpy and matplotlib to function the code for showing the graph and the calculation for numpy.

Next, we created a function to calculate the temperature at every thousandth of a second, as follows:

def calculate (pointinmid, calcmatrix, time, coeff, currtime = 1):

for cal in range (1, pointinmid-1):
calcmatrix [currtime] [cal] = calcmatrix [currtime-1] [cal] + coeff * (calcmatrix [currtime-1] [cal-1] +
calcmatrix [currtime-1] [cal + 1] – (2 * calcmatrix [currtime-1] [cal]))
print (calcmatrix [currtime] [cal])
print (“———————————————-” )
currtime + = 1
if (currtime <= time):
return calculate (pointinmid, calcmatrix, time, coeff, currtime)
else:
return calcmatrix
By putting pointinmid, calcmatrix, time, coeff, currtime = 1, as parameters in function, we will implement the formula

Tl + 1i = Tli + λTli + 1-2Tli + Tli-1
Where
λ = kt / (x) 2.
Next we create a ‘user input interaction’ where the user can determine the conditions that will determine the results of this research, as follows:

coeff = float (input (“Thermal conductivity:”))
x = float (input (“Length of the rod:”))
fronttemp = float (input (“Front temperature:”))
backtemp = float (input (“Back Temperature:”))
time = int (input (“Time:”))
pointinmid = int (input (“Total of Points between front and back:”))
The above input will determine the factors in the temperature difference in a stick. When running code, after we type the following input, intmid point will increase, deltax value x divide pointintmid. For coordx, we use the array to calculate the delta times of the rod by using a loop of (pointinmid + 1). Fronttemp is the starting point in a stick and also the initial temperature on a stick. Backtemp is the end point in a stick and also the last temperature on a stick.

Code of the final result:

pointinmid + = 1
deltax = x / pointinmid
coordx = np.array ([deltax * cordx for cordx in range (pointinmid + 1)])
pointinmid + = 1
initial = np.array ([[0.0 for i in range (pointinmid)] for j in range (time + 1)])
for l in range (time + 1):
initial [l] [0] = fronttemp
initial [l] [- 1] = backtemp
xtest = calculate (pointinmid, initial, time, coeff)
Example input:

 

Coeff = 0.1
X = 100cm
Fronttemp = 100 ° C
Backtemp = 50 ° C
Time = 10
Point in mid = 4

Final:

plt.figure (1); plt.clf ()
pl = plt.subplot ()
for h in range (time + 1):
pl.plot (coordx, xtest [h], “- o”)
pl.set_xlabel (“rod”)
pl.set_ylabel (“Temperature”)
plt.show ()

 

 

 

 

 

P.S. the program result can only be seen by my partner Nicander or Felix

Members:

Alfi  – 2101693574
Felix – 2101693851
Nicander 2101693113

Jul 10

Programming Languages Project

Information Comments Off on Programming Languages Project

Introduction

We’ve decided to make a java web application using database via MVC pattern.  To make a web application we use a glassfish server and primefaces.

Project Specification

Non functional:

– Availability.

– Recoverability.

– Maintainability.

 

Solution Design

Program Manual

Data Structures we used is an arraylist. It inherits AbstractList class and implements List interface. Java ArrayList allows us to randomly access the list and others i.e. implementing operators, etc.

Create a new web application. Now we make a database by creating a new java asp entity from database, we uses the model view controller file via mysql. The files made are in xhtml for the web. And it makes the packages for the navigating pages and the other for making the CRUD function.

The WEB-INF folder divides into the faces-config, glassfish-resources and web.xml the main requirements for running the program.  The games folder is in xhtml files as the algorithm explains the CRUD function when we click the links on the web.

Next, we go through the packages where is the main control of the program. First we go to the database.model package. First we make the abstract facade class. We import lists, validation, xml and the persistence so that it can create and remove persistent entity instances, to find entities by their primary key, and to query over entities.

The Games file shows the id name price and quantity by using set() and get() function to make the list. Implement serializable so that it can be saved to a database or transferred over a network. The @NamedQueries shows the command of the database for reading the database. For the overriding method, hashCode() Returns a hash code value for the object for the tables. And for toString() function the non string function are automatically converted to string.

The GamesController describes the selected lists when clicking on one of them. As from the previous, we implement serializable so it can save the database. Here we import jsfutil and pagination helper so that we can go navigate page by page. We make the Games, DataModel, gamesfacade, paginationhelper class private. TThen we make another class as static GamesControllerConvert by implementing converter so that it can convert to string. In the GamesFacade package we extend from the abstract class so it controls the entity manager by using inheritance.

We have the database.model.util. In the JsfUtil file, we import the javax faces and make the class abstract. The FacesContext represents all of the contextual information associated with processing an incoming request, and creating the corresponding response for the database.

Solution

 

 

 

 

 

 

 

References: https://www.youtube.com/watch?v=q-CzqROtoko Video Demo: https://drive.google.com/file/d/1-08wZb1lomLDlSpnKVpvReS0FGQ30oxo/view?usp=sharing Git link: https://github.com/alfir3dz1/programminglanguagesfinal

 

Members:

Alfi – 2101693574

Jason – 2101693510

Tama –  2101710920