Calculating Fourier series in SciPy

Googlebot

The general solution for heat transport in a metal bar with insulated heads is enter image description here

I tried to calculate the gradient at a given time for a typical case where the initial temperature difference is 100 with

import numpy as np
import matplotlib.pyplot as plt

x = np.linspace(0,3,100)
L = 3
n_max = 20

def bn(n):
    n = int(n)
    if (n%2 != 0):
        return 400/(np.pi**2*n**2)
    else:
        return 0

def wn(n):
    global L
    wn = (np.pi*n)/L
    return wn

def fourierSeries(n_max,x,t):
    a0 = 100/2
    partialSums = a0
    for n in range(1,n_max):
            partialSums = partialSums + bn(n)*np.exp(-.00001*wn(n)**2*t)*np.cos(wn(n)*x)
    return partialSums

u = []
for i in x:
    u.append(fourierSeries(n_max,i,1))

plt.plot(x,u)

but the result is not what expected enter image description here

what is possibly wrong with the code?

prometeu

I belive that you missed the temperature function of the rod:

f(x) = T + 100/L * x

Using this, and calculating the integral will do the job.

import numpy as np
import matplotlib.pyplot as plt

x = np.linspace(0,3,100)
L = 3
n_max = 20

def bn(n):
    b=200/n**2/np.pi**2*(np.cos(n*np.pi)-1)
    return b

def wn(n):
    wn = (np.pi*n)/L
    return wn

def fourierSeries(n_max,x,t):
    a0 = 100/2
    partialSums = a0
    for n in range(1,n_max):
        partialSums = partialSums + bn(n)*np.exp(-.0005*wn(n)**2*t)*np.cos(wn(n)*x)
    return partialSums

u = []
hour = 3600
for i in x:
    u.append(fourierSeries(n_max,i,2*hour))

plt.plot(x,u)

And the graph:

After 30 minutes one end will have temp=35 and the other end temp=65

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Create scipy curve fitting definitions for fourier series dynamically

From Dev

Fourier series - Plot in Matlab

From Dev

For Loop for a Fourier Series Equation

From Dev

Fourier series coefficients gnuplot

From Dev

Calculating derivative by SciPy

From Dev

fftshift before calculating fourier transform: Matlab

From Dev

Calculate the Fourier series with the trigonometry approach

From Dev

Sympy extract Fourier Series coefficients

From Dev

Sympy extract Fourier Series coefficients

From Dev

Calculating nested radical series

From Dev

Calculating Aroon Indicator Series

From Dev

calculating windowed probabilities in numpy/scipy

From Dev

Fast Fourier Transform and Clustering of Time Series

From Dev

My fourier series doesn't fit the graph

From Dev

Fast Fourier Transform and Clustering of Time Series

From Dev

How to perform convolution using Fourier Series

From Dev

My fourier series doesn't fit the graph

From Dev

How to vectorize fourier series partial sum in numpy

From Dev

calculating slope for a series trendline in Pandas

From Dev

Calculating multiindex series / dataframes with conditions

From Dev

calculating the autocorrelation of a time series in R

From Dev

Calculating relative time series in R

From Dev

calculating slope for a series trendline in Pandas

From Dev

Calculating Kendall's tau using scipy and groupby

From Dev

calculating the number of k-combinations with and without SciPy

From Dev

Does Wavwrite or Audiowrite do some Windowing and Fourier Series with some distribution?

From Dev

Matlab: How to plot this fourier series, where each index is odd

From Dev

Plotting Fourier Series coefficients in Python using Simpson's Rule

From Dev

Taylor Series Calculating Program in C compiled with GCC

Related Related

  1. 1

    Create scipy curve fitting definitions for fourier series dynamically

  2. 2

    Fourier series - Plot in Matlab

  3. 3

    For Loop for a Fourier Series Equation

  4. 4

    Fourier series coefficients gnuplot

  5. 5

    Calculating derivative by SciPy

  6. 6

    fftshift before calculating fourier transform: Matlab

  7. 7

    Calculate the Fourier series with the trigonometry approach

  8. 8

    Sympy extract Fourier Series coefficients

  9. 9

    Sympy extract Fourier Series coefficients

  10. 10

    Calculating nested radical series

  11. 11

    Calculating Aroon Indicator Series

  12. 12

    calculating windowed probabilities in numpy/scipy

  13. 13

    Fast Fourier Transform and Clustering of Time Series

  14. 14

    My fourier series doesn't fit the graph

  15. 15

    Fast Fourier Transform and Clustering of Time Series

  16. 16

    How to perform convolution using Fourier Series

  17. 17

    My fourier series doesn't fit the graph

  18. 18

    How to vectorize fourier series partial sum in numpy

  19. 19

    calculating slope for a series trendline in Pandas

  20. 20

    Calculating multiindex series / dataframes with conditions

  21. 21

    calculating the autocorrelation of a time series in R

  22. 22

    Calculating relative time series in R

  23. 23

    calculating slope for a series trendline in Pandas

  24. 24

    Calculating Kendall's tau using scipy and groupby

  25. 25

    calculating the number of k-combinations with and without SciPy

  26. 26

    Does Wavwrite or Audiowrite do some Windowing and Fourier Series with some distribution?

  27. 27

    Matlab: How to plot this fourier series, where each index is odd

  28. 28

    Plotting Fourier Series coefficients in Python using Simpson's Rule

  29. 29

    Taylor Series Calculating Program in C compiled with GCC

HotTag

Archive