Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 23131

Plotting a hysteresis curve

$
0
0

I need to plot a hysteresis curve with given values of B and H, but, obviously it won't and definitely shouldn't give a nice straight line. My question is, considering my very beginner skills in python, is there a way I can place all my data onto a graph and connect them with a curve that looks like a hysteresis curve?

This is my code so far

import matplotlib.pyplot as pltimport numpy as np# Section 1: Calculating values of H for toroid A# defining the values to find H for toroid AN_1 = 3420L_1 = 0.076R_1 = 8# defining function to find the value of H with given V_1def H_toroid_A(V_1):    return (V_1 * N_1) / (L_1 * R_1)# Section 2: Calculating the delta list of uncertainties for H toroid A# defining variables and uncertaintiesV_1_values = [3, 8, 1, 10, 5]delta_V_1_values = [0.1, 0.2, 0.05, 0.3, 0.15]  # uncertainties for V_1delta_N_1 = 0  # uncertainty for N_1delta_L_1 = 0.001  # uncertainty for L_1delta_R_1 = 0.4  # uncertainty for R_1# function to calculate uncertainties in Hdef calculate_uncertainty_H(V_values, delta_V_values, delta_N, delta_L, delta_R):    uncertainties = []    for i in range(len(V_values)):        uncertainty_H = np.sqrt(            ((V_values[i] / (L_1 * R_1)) * delta_N)**2 +            ((N_1 / (L_1 * R_1)) * delta_V_values[i])**2 +            ((-V_values[i] * N_1 / (L_1**2 * R_1)) * delta_L)**2 +            ((-V_values[i] * N_1 / (L_1 * R_1**2)) * delta_R)**2        )        uncertainties.append(uncertainty_H)    return uncertaintiesuncertainties_H = calculate_uncertainty_H(V_1_values, delta_V_1_values, delta_N_1, delta_L_1, delta_R_1)# Section 3: Calculating values of B for toroid A# defining the values to find B for toroid AR_2 = 270000C = 220e-9N_2 = 820A_2 = 9.025e-5# defining function to find the value of B with given V_cdef B_toroid_A(V_c):    return (R_2 * C * V_c) / (N_2 * A_2)# Section 4: Calculating list of uncertainties for B toroid A# defining variables and uncertaintiesV_c_values = [3, 8, 1, 10, 5]delta_V_c_values = [0.1, 0.2, 0.05, 0.3, 0.15]  # uncertainties for V_cdelta_N_2 = 0  # uncertainty for N_2delta_C = 1.1e-8  # uncertainty for Cdelta_A_2 = 5e-8  # uncertainty for A_2delta_R_2 = 13500  # uncertainty for R_2# function to calculate uncertainties in Bdef calculate_uncertainty_B(V_values, delta_V_values, delta_N, delta_C, delta_A, delta_R):    uncertainties = []    for i in range(len(V_values)):        uncertainty_B = np.sqrt(            ((C * V_values[i]) / (N_2 * A_2))**2 * delta_R_2**2 +            ((R_2 * V_values[i]) / (N_2 * A_2))**2 * delta_C**2 +            ((R_2 * C) / (N_2 * A_2))**2 * delta_V_values[i]**2 +            ((R_2 * C * V_values[i]) / (N_2 * A_2**2))**2 * delta_A_2**2 +            ((R_2 * C * V_values[i]) / (N_2**2 * A_2))**2 * delta_N_2**2        )        uncertainties.append(uncertainty_B)    return uncertaintiesuncertainties_B = calculate_uncertainty_B(V_c_values, delta_V_c_values, delta_N_2, delta_C, delta_A_2, delta_R_2)# Section Alpha: calculating list of values of HH_values = [H_toroid_A(V_1) for V_1 in V_1_values]# Section Beta: calculating list of values of BB_values = [B_toroid_A(V_c) for V_c in V_c_values]# Plottingplt.figure(figsize=(8, 6))plt.errorbar(H_values, B_values, xerr=uncertainties_H, yerr=uncertainties_B, fmt='o')plt.xlabel('H (Intensité du champ magnétique)')plt.ylabel('B (Densité du flux magnétique)')plt.title('Courbe Hysteresis')plt.grid(True)plt.show()

Right now, from what I can find, most of hysteresis curve in python suggestions are REALLY complicated and doesn't suit the data I have, because I'm not starting from scratch, I have given values that should connect together to form the appropriate curve. THE DATA RIGHT NOW IS A PLACE HOLDER, it's normal that it gives a linear curve.

I suppose it isn't much help without the actual data, but I don't have access to it at the moment.

Any suggestions are very welcome


Viewing all articles
Browse latest Browse all 23131

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>