A list of puns related to "Finite difference"
I'm watching a video on finite Calculus right now, i.e. Calculus on discrete sets. The analogue of derivation in this method of Calculus is differences, and so β f(x) = f(x + 1) - f(x). The video, though, doesn't explain why exactly β f(x) is taken as the difference between f(x + 1) - f(x), and not f(x) - f(x - 1). My question, then, is why is that? What justification is there for describing the difference as the former and not the latter?
Can I know if there is any website/resource that explains how to solve fin numericals using Gauss-Seidel iteration method to obtain temperature distribution curve? I searched the web and couldn't find any. It'll be useful if the source contains how to solve the problem in MATLAB to obtain the TD curve
Hello there, I am looking for software or scripts for waveform propagation scripts or software (either finite element or finite differences) that allows for viscoelasticity (and, ideally, for anisotropy as well). Currently, I am testing SOFI2D, SOFI3D, and Comsol.
Any suggestions?
Thanks!
sparsity structure of coefficient matrix
I have a coefficient matrix which is obtained through finite difference discretization of a 4d dirac equation in terms of the 12 unknown(4 spins and three colours) with 4 points in each dimension of the space time.Overall this sparse matrix has a size of 3072 x 3072 and its sparsity pattern is shown in the image "sparsity structure of coefficient matrix".I am interested to obtain some specific mass dependent blocks in the matrics(these blocks are obtained when one fixes each of the four spins and write the equation of the three colours for each spin.)
If I dig deep into the structure of the matrics ,then I observe the following pattern repeated every 48 diagonal points as shown in thr imagestructure.I can not deduce any equation ordering from this structure.
My question is how can i find out how the 12 equations for each grid point is ordered and which permutation can help me to achieve the desired structure where colours are arranged per spin.Has anyone worked with a 4d finite difference ?
I searched a lot and found methods such as Gelerkin and collocation methods and can anyone confirm if these are similar to finite difference analysis ? My condition is they have to be discretization methods.
Apparently I mixed these two up in my FEA class. We were solving a problem for homework where we had to calculate the stresses and deflections in an I-beam, and divide it into 3 sections (the two flanges and the web). The question explicitly asked to use the direct method of solving, and I got the correct answers, but my prof told me that the direct method is the same as the finite element method...
To be clear, he wanted me to solve it this way:
{stiffness matrix}*{deflections} = {reaction forces}
As opposed to what I thought was the "direct method":
deflection = (PL)/(AE)
Any clarification is greatly appreciated
I'm a PhD physicist, working in the field of optics and photonics.
Many of our problems and simulations are hugely complex, run on background servers which are expensive to maintain, and which aren't running 100% of the time. Upgrading these servers in the lab happens every few years, but again - at a huge cost.
Id be interested in offloading these tasks onto a decentralized computational engine which is "pay to play" - in that I pay small amounts of ADA tokens for people to solve a set of paralleled equations.
In particular, I'd be interested in solving the finite difference time domain problem as per Maxwell's equations.
There already exists a fairly substantial set of code for these solvers - such as lumerical, etc... I really just want to know if I can produce a dApp which solves the problem instead of doing it on my own machine.
for a better idea of exactly what type of problem I'm trying to solve, read this comment I posted : https://www.reddit.com/r/CardanoDevelopers/comments/lpuytp/limits_of_cardano_decentralized_physics_computing/godyk8x?utm_source=share&utm_medium=web2x&context=3 .
Hello, I am in the midst of writing my dis, and I need help with deriving the finite difference method, for time.
I understand how to derive the finite difference approx (forward, backward, central and symmetric) is formed by manipulating the Taylor series -
however I would like to know how the finite difference method is derived via a similar method to above, for time. (for forward, backward, central and symmetric)
Any explanations, links to videos or textbooks would be greatly appreciated
thank you !
Hi, I'm trying to solve the poisson equation in 2D and I'm wondering if there's any already existing finite difference solvers for this problem. I have a large 2D numpy array containing the source terms and I need to apply neumann and dirichlet boundaries on different regions. I thought there would already be many solvers for this because it's such a common equation but the only straightforward one I found was FENICS project, but it uses Finite Elements which seems a bit overkill in this case.
Coding this from scratch myself seems like I'm reinventing the wheel especially because I will need the code to scale, so I came here to be pushed in the right direction and if I've missed any libraries that do this.
I need help to formulate this q into code
https://preview.redd.it/98kjjhc5dl571.png?width=707&format=png&auto=webp&s=4a3887b691ba74ee0c82954674f006f9dfffc70d
% ATTEMPT AT CODE%
clear all
clc
close all
L=0.05;
nt=500;
n=5;
edot=6e5;
k=34;
g=edot/k;
dx=L/n;
alp=1/(dx)^2;
h=60;
syms T5
T_inf=30;
T0=ones(1,n);
T1=ones(1,n);
%T0(5)=T5;
for i=1:n-1
T1(i)=(alp)*(T0(i+1)-2*T0(i)+T0(i-1))+g; % node 1( insulated) & 2 3 4
end
T0(end)=h*(T_inf-T(5))*k*1/dx+edot*dx/2; % node 5 with conv
https://preview.redd.it/jffokz7zcl571.png?width=605&format=png&auto=webp&s=3fc1ba7ec805d0a585391da6a398c67f9200001c
When an aircraft is being tracked by radar the position of the aircraft is determined by distance (calculated from the return time of pulse) and the sweep angle of the radar. To give a meaningful radar display this information needs to be converted to cartesian coordinates and velocity and acceleration (both vectors) need to be calculated. Write a program to perform this operation (use centered finite differences (second-order correct)) and test your program with the data shown in the table below.
https://preview.redd.it/0tsxac7894s61.png?width=702&format=png&auto=webp&s=f26976bfcc751f64fc7e6842bfc244be16dea61f
I've done the easy part of converting it to cartesian. But I have no idea what to do next. If you can nudge me to the right direction that would be appreciated :)
I made a forward fd-discretization of the Cauchy-Riemann PDEs (look at the picture) but I am struggling to implement this in python.
I have a quadratic mesh with heigh = 2*pi. The dirichlet boundary conditions are at u(x,0) = f(x) = cos(x) and v(x,0) = g(x) = sin(x). And I have periodic boundary conditions: u(2pi,y) = u(0,y) and v(2pi,y) = v(0,y).
My code: https://github.com/rico227/cauchy-riemann-fd
I expect the plot to look like the complex e-function u (x, y) + iv (x, y) = exp (ix β y) but when I plot U or V there is only the integral of sinus or cosinus respectively plotted. I am not sure if my nested for loop does what I want or if I have a lack of understanding how to plot this right. Does anyone have an idea how to solve this?
https://preview.redd.it/k16djpbi9oe61.png?width=606&format=png&auto=webp&s=7d40a6934be6b481e6910da6e02313f653a77807
If anyone has a minute to step away from the ~stonks~ and help me with this homework question I would be super grateful! The question is as follows:
Write a matlab routine that solves the two-dimensional Poisson's equation, (del)u = f(x; y); in the domain x = [0; Lx] and y = [0; Ly] subject to the following Dirichlet boundary conditions on the boundaries:
u(x, 0) = sin(x); u(x, Lx) = sin(x)*cos(Ly); u(0, y) = 0; u(Lx, y) = sin(Lx)*cos(y)
Assume a uniform grid with Nx and Ny equally spaced points in the x and y directions, respectively. Build the full matrix (i.e. don't use a sparse matrix), and show that you get second-order accuracy using the test solution:
u(x, y) = sin(x)*cos(y)
for Lx = Ly = 8: Use an equal number of points in each direction, Nx = Ny = N: Note that you will need to build the required forcing term f(x, y).
I have a code that is working, but it does not match up with the analytical solution and I have no idea why. I've been working on it all day and I just can't look at it anymore. I appreciate any help, thank you in advance! I have pasted what I have below.
clear all; close all;
% length of the area to be solved
Lx = 8; Ly = 8;
% number of grid points
Nx = 100; Ny = 100;
% grid points in the x-direction
dx = Lx/(Nx-1);
for i = 1:Nx
xx(i,1) = (i-1)*dx;
end
% grid points in the y-direction
dy = Ly/(Ny-1);
for i = 1:Ny
yy(i,1) = (i-1)*dy;
end
% initialize the size of matrix AA and vector cc
AA = zeros(Nx*Ny,Nx*Ny);
cc = zeros(Nx*Ny,1);
% apply BCs on lower/upper boundaries
for j = 1:Nx
% lower wall (y = 0)
row = j;
AA(row,row) = 1.0;
cc(row) = sin(xx(j))*cos(yy(1));
% upper wall (y = Ly)
row = Nx*(Ny-1)+j;
AA(row,row) = 1.0;
cc(row) = sin(xx(j))*cos(yy(Ny));
end
% apply BCs on left/right boundaries
for i = 2:Ny-1
% left wall (x = 0)
row = i;
AA(row,row) = 1.0;
cc(row) = sin(xx(1))*cos(yy(i));
% right wall (x = Lx)
row = Nx*(Ny-1)+i;
AA(row,row) = 1.0;
cc(row) = sin(xx(Nx))*cos(yy(i));
end
% interior grid points
for i = 2:Ny-1
for j = 2:Nx-1
row = (i-1)*Nx+j;
AA(row,row) = -2.0*(1.0/(dx*dx) + 1.0/(dy*dy));
AA(row-1,row) = 1.0/(dx*dx) + 1.0/(dy*dy); % west stencil point, x(j-1)
AA(row+
... keep reading on reddit β‘This is the solutions given. What I don't understand is the yellow highlighted part. Why must we add in t= analytical? What is it for? And how do we get the numbers?
https://preview.redd.it/kjdhjr8kn2f61.png?width=886&format=png&auto=webp&s=b8335e8148b22ea0301df384e06fb7211ba704ec
Next semester I have to take a finite mathematics course. So far Iβve taken college algebra and Iβm about to finish up calculus. I found them both to be about equally as challenging but nothing crazy. Now Iβm stepping down to a lower math since itβs a prerequisite for my degree which happens to be finite math. What should I expect? And will the fact that I went straight to calculus and stepping down mess me up? Is it just as challenging as calculus or college algebra? Thanks...
Has anyone studied finite differences equation? Can anyone guide me how to start witht the convergence results question please? Thanks!
https://preview.redd.it/op12ox57mwc61.png?width=747&format=png&auto=webp&s=4ec56d5805e9bc9870d79dc60b5559dfc505ec5d
I honestly can't think where else to post this so here I am hoping somebody somewhere has the answer.
I'm writing a program to price European call options with all the usual inputs and it basically works, but when the problem gets big, my program completely shits the bed.
Basically it works like this:
I have some regular boundary conditions. When the asset price is zero, the option is worthless. When the time to expiry is zero, the option is worth the asset price minus the strike price, and when the asset price is the max considered, it is the same except I'm gonna discount the option proportional to tau. If you're familiar with this sort of problem, you hopefully already know what I'm trying to describe.
Now the iterative process begins!
My program cycles through the table starting from time to expiry (on the x-axis if you like) equals 0 until it finds an asset price (y-axis) which doesn't render the option completely worthless. Say the exercise price is 100, then the program will stop at 100, take option values for 99, 100 and 101 based upon the boundary conditions, do some formula and spit out a value for asset price 100, tau equals 1. It will do this until it reaches the final value before the max (since these were solved by the boundary conditions), and then it will loop through the table again, this time from tau equals 1, and it will do this all the way until the table is full.
I have tested this formula. I have worked it out on pen and paper and compared it with the results from the computer. I have followed the results for asset price 100 all the way until tau is 360 and it works beautifully. Every single value for tau = 1, 2, 3, etc, they all work perfectly, so why god please why does it suddenly explode and start spitting out values so large I cause an overflow?
When I run the program using much simpler inputs, for example only 10 asset price steps and only 12 expiry time steps, it just works, so what is actually happening?????
Will post code in a minute.
i found a code for the 1d heat equation in this video, and I'm not super well-versed in linear algebra, so I can't quite decipher the mechanism here.
# Heat Equation using matrices
using SparseArrays
using LinearAlgebra
using Plots
#create a m x n plate
n = 50 # y-axis
m = 50 #x-axis
u = zeros(n, m+1)
Ξt = 1/m
Ξx = 1/n
x = Array((0:n) * Ξx)
a = 5.0
b = 2.0
k = a .+ b*x
Ξ» = k * Ξt/(Ξx^2)
F = ones(n, m) * Ξt
Ξ»_up = -Ξ»[1:n-1]
Ξ»_up[1] *= 2
A = spdiagm(-1 => -Ξ»[2:n], 0 => 2Ξ»[1:n] .+ 1, 1 => Ξ»_up)
for i = 1:m
u[:, i+1] = A\(u[:, i] + F[:, i])
end
Plots.plot(u[1,:])
i'm having trouble especially with this block:
Ξ» = k * Ξt/(Ξx^2)
F = ones(n, m) * Ξt
Ξ»_up = -Ξ»[1:n-1]
Ξ»_up[1] *= 2
A = spdiagm(-1 => -Ξ»[2:n], 0 => 2Ξ»[1:n] .+ 1, 1 => Ξ»_up)
for i = 1:m
u[:, i+1] = A\(u[:, i] + F[:, i])
end
how exactly does this code work? i'm not too familiar with the arrays/matrices and operators used here. if someone could explain it line-by-line or function by function, that would be duly appreciated. thank you for the help and sorry for the trouble!
Given that a finite difference method like Euler or Crank-Nicolson is essentially an integration process, during which errors should get smoothed out, is there any advantage to using doubles instead of floats? Does the speed advantage of floats translate into any *actual* loss of precision?
Hi all, I'm very new to programming using numba (just started today!) and I'm trying to write code that calculates partial derivatives of a 2D array, trying to use my GPU to speed things up. I have existing serialized code to compare results to.
Here's the code I have so far.
from numba import cuda
import numpy as np
import matplotlib.pyplot as plt
@cuda.jit
def xdiff(outx,dx,deg,u):
#outx is a numpy array with the same dimensions and dtype as u
#dx is a float
#deg is an int
#u is a (Nx,Ny) numpy array created elsewhere where Nx and Ny are the dimensions
x,y = cuda.grid(2)
if x < u.shape[0] and y < u.shape[1]:
if deg == 1:
outx[x][y] += (-u[x][y+2] +8*u[x][y+1] -8*u[x][y-1] +u[x][y-2])/(12*dx)
#higher degree derivative code
threadsperblock = (32,32)
blockspergrid = ((u.shape[0] + (threadsperblock[0] - 1)) // threadsperblock[0],(u.shape[1] + (threadsperblock[1] - 1)) // threadsperblock[1])
outx = np.zeros(u)
dx = 0.1
deg = 1
u = np.load(#file#)
xdiff[blockspergrid, threadsperblock](outx,dx,deg,u)
plt.imshow(outx)
I want to implement periodic boundary conditions in this discretization, but I'm having trouble with this. I'm quite sure that the problem is with the boundary, as if I change
if x < u.shape[0] and y < u.shape[1]:
to
if x < u.shape[0]-1 and y < u.shape[1]:
The resulting image looks exactly as expected, except for one row/column along the edge that's just set to 0. I'd appreciate any insight!
Please note that this site uses cookies to personalise content and adverts, to provide social media features, and to analyse web traffic. Click here for more information.