0% found this document useful (0 votes)
6 views5 pages

Ibrahim Assignment 2

The document outlines an assignment for MME-382 Numerical Analysis and Applications in Materials, submitted by Mohammad Ibrahim. It involves using Python to compute the first and second derivatives of five datasets relevant to Metallurgy and Materials Engineering, including stress-strain data and temperature vs resistivity. The assignment also includes plotting the original data, first derivative, and second derivative for each dataset.

Uploaded by

Muhammad Ibrahim
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views5 pages

Ibrahim Assignment 2

The document outlines an assignment for MME-382 Numerical Analysis and Applications in Materials, submitted by Mohammad Ibrahim. It involves using Python to compute the first and second derivatives of five datasets relevant to Metallurgy and Materials Engineering, including stress-strain data and temperature vs resistivity. The assignment also includes plotting the original data, first derivative, and second derivative for each dataset.

Uploaded by

Muhammad Ibrahim
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

MME-382 Numerical Analysis and Applications in Materials

Department of Metallurgy and Materials Engineering

Assignment 02

Name Mohammad Ibrahim

Reg No. 12-3-1-025-2022

Submitted to Dr. Zaheer Asghar

Date 14 April,2025
Question:Use 5 data sets with atleast each having 8 values perform its 1st and 2nd derivatives
and plot its graph using python the data must be according to field of Metallurgy and
Materials Engineering.

Ans

Note: Here I use python also to calculate derivatives.

import numpy as np

import matplotlib.pyplot as plt

# Helper function to compute derivatives

def compute_derivatives(x, y):

dy_dx = np.gradient(y, x) # First derivative

d2y_dx2 = np.gradient(dy_dx, x) # Second derivative

return dy_dx, d2y_dx2

# Dataset 1: Stress-Strain (Tensile Test)

strain = np.linspace(0, 0.02, 10)

stress = np.array([0, 50, 100, 150, 200, 250, 275, 285, 290, 292])

stress_d1, stress_d2 = compute_derivatives(strain, stress)

# Dataset 2: Temp vs Electrical Resistivity

temp = np.linspace(0, 900, 10) # in °C

resistivity = np.array([1.5, 2.1, 2.9, 3.8, 4.9, 6.1, 7.5, 9.0, 10.6, 12.3]) # µΩ·cm

res_d1, res_d2 = compute_derivatives(temp, resistivity)

# Dataset 3: Grain Size vs Yield Strength (Hall-Petch)

grain_size = np.array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])


yield_strength = 500 + 100 / np.sqrt(grain_size) # Simplified Hall-Petch

ys_d1, ys_d2 = compute_derivatives(grain_size, yield_strength)

# Dataset 4: Time vs Hardness (Age Hardening)

time = np.linspace(0, 10, 10) # in hours

hardness = np.array([100, 120, 140, 160, 180, 185, 180, 160, 130, 100])

hard_d1, hard_d2 = compute_derivatives(time, hardness)

# Dataset 5: Cooling Rate vs Grain Size

cool_rate = np.linspace(1, 10, 10)

gr_size = 100 / np.sqrt(cool_rate) # finer grains at higher rates

gs_d1, gs_d2 = compute_derivatives(cool_rate, gr_size)

# Plotting

datasets = [

(strain, stress, stress_d1, stress_d2, 'Strain', 'Stress (MPa)', 'Stress-Strain Curve'),

(temp, resistivity, res_d1, res_d2, 'Temperature (°C)', 'Resistivity (µΩ·cm)', 'Temp vs


Resistivity'),

(grain_size, yield_strength, ys_d1, ys_d2, 'Grain Size (µm)', 'Yield Strength (MPa)', 'Grain Size
vs Strength'),

(time, hardness, hard_d1, hard_d2, 'Time (h)', 'Hardness (HV)', 'Time vs Hardness'),

(cool_rate, gr_size, gs_d1, gs_d2, 'Cooling Rate (°C/s)', 'Grain Size (µm)', 'Cooling Rate vs Grain
Size')

plt.figure(figsize=(18, 15))

for i, (x, y, d1, d2, xlabel, ylabel, title) in enumerate(datasets):


plt.subplot(5, 3, i * 3 + 1)

plt.plot(x, y, 'o-', label='Original')

plt.title(f'{title} - Original')

plt.xlabel(xlabel)

plt.ylabel(ylabel)

plt.grid(True)

plt.subplot(5, 3, i * 3 + 2)

plt.plot(x, d1, 's-', color='orange', label='1st Derivative')

plt.title(f'{title} - 1st Derivative')

plt.xlabel(xlabel)

plt.ylabel('First Derivative')

plt.grid(True)

plt.subplot(5, 3, i * 3 + 3)

plt.plot(x, d2, 'd-', color='green', label='2nd Derivative')

plt.title(f'{title} - 2nd Derivative')

plt.xlabel(xlabel)

plt.ylabel('Second Derivative')

plt.grid(True)

plt.tight_layout()

plt.show()

You might also like