differential-equations

Adapting initial-value problem to boundary-value problem using scipy.integrate.solve_bvp?

≡放荡痞女 提交于 2020-04-18 06:32:12
问题 I would like to adapt an initial-value-problem (IVP) to a boundary-value-problem (BVP) using scipy.integrate.solve_bvp . A similar question was asked here, but I do not follow everything explained in the answer. The example below regarding the SIR model was taken from this website. Here, the initial condition y0 is taken to be the initial value of S , I , and R at time x0[0] . This system of ODEs is given by the function SIR below, which returns [dS/dt, dI/dt, dR/dt] over the interval from x

Runge Kutta (RK4) 2nd order DE in C++ ERROR CODE

别等时光非礼了梦想. 提交于 2020-01-25 04:14:30
问题 I am receiving an error that I have never recognized before. For some background as to what this code is, I am writing a algorithm with Runge-Kutta to solve a second order differential equation (the angle of a pendulum in relation to time). Even as I am typing this I already know there are probably many errors in this. This is part of my final project in my first ever coding course. Any help I can get, in the simplest language possible, could really help! Here is the ERROR code second_order

How to make the python code with two for loop run faster(Is there a python way of doing Mathematica's Parallelize)?

大憨熊 提交于 2020-01-24 15:36:08
问题 I am completely new to python or any such programming language. I have some experience with Mathematica. I have a mathematical problem which though Mathematica solves with her own 'Parallelize' methods but leaves the system quite exhausted after using all the cores! I can barely use the machine during the run. Hence, I was looking for some coding alternative and found python kind of easy to learn and implement. So without further ado, let me tell you the mathematical problem and issues with

C++ program has stopped working- Solving ordinary differential equations

你离开我真会死。 提交于 2020-01-24 12:18:33
问题 I'm writing a C++ program to find solutions for first order differential equations for a college assignment. The program starts up and then once I enter the number of iterations to do I get the error message "Euler's method.exe has stopped working". This is my code: #include <functional> #include <vector> using namespace std; double f_r(double x, double r) { return r; } double f_s(double x, double s) { return -x/s; } double eulerstep(const function<double(double,double)>& f, double xsub0,

Matlab Euler Explicit ode solver with adaptable step, is there a way to make code faster?

泄露秘密 提交于 2020-01-24 00:39:32
问题 I am trying to find a way to make this code faster. Nagumo1 is the function that calculates the value of the two derivatives at time t. function x = nagumo(t, y, f) Iapp = f(t); e = 0.1; F = 2/(1+exp(-5*y(1))); n0 = 0; x = zeros(2, 1); z(1) = y(1) - (y(1).^3)/3 - y(2).^2 + Iapp; %z(1) = dV/dt z(2) = e.*(F + n0 - y(2)); %z(2) = dn/dt x = [z(1);z(2)]; end It is a system of differential equations that represents a largely simplified model of neuron. V represents a difference of electric

Generate DifferentialEquations ifrom a vector in Julia

你说的曾经没有我的故事 提交于 2020-01-16 08:40:34
问题 I have created a vector which concatenates strings of differential equations that are in the correct format to be used be the differeq ode sovler in Julia (i.e, f(du,u,p,t): Combine <- c("du[1] = - 1*0.4545*(u[1]^1) - 1*27000000*(u[4]^1)*(u[1]^1)", "du[2] = - 1*3100000000*(u[2]^1)*(u[4]^1)", "du[3] = - 1*33000*(u[3]^1)*(u[4]^1)", "du[4] =2*0.4545*(u[1]^1) - 1*3100000000*(u[2]^1)*(u[4]^1) - 1*33000*(u[3]^1)*(u[4]^1) - 1*27000000*(u[4]^1)*(u[1]^1) - 1*8500000*(u[4]^1)*(u[5]^1) - 1*390000000*(u

How to solve DAE with a varying input / a time-dependent input function in Matlab?

瘦欲@ 提交于 2020-01-13 14:50:38
问题 I'm solving a DAE problem with ode15i solver. I have 8 variables and 8 equations, and the system is complex that the only working solver so far is ode15i. I've used the guide: http://se.mathworks.com/help/symbolic/set-up-your-dae-problem.html. However, this guide doesn't help me to solve the problem with a varying input. My system has a time-dependent input, a function. The function itself is quite simple, but the problem is that the time t in DAE system is in symbolic form, and my input

Make sure MATLAB does not recalculate symbolic expression

邮差的信 提交于 2020-01-11 07:14:10
问题 I am building (my first...) MatLab program, it needs to differentiate an equations symbolically and then use this solution many many times (with different numeric inputs). I do not want it to recalculate the symbolic differentiation every time it needs to put in a new set of numeric values. This would probably greatly add to the time taken to run this program (which - given its nature, a numeric optimiser, will probably already be hours). My question is how can I structure my program such

How to solve differential equation using Python builtin function odeint?

情到浓时终转凉″ 提交于 2020-01-11 05:25:08
问题 I want to solve this differential equations with the given initial conditions: (3x-1)y''-(3x+2)y'+(6x-8)y=0, y(0)=2, y'(0)=3 the ans should be y=2*exp(2*x)-x*exp(-x) here is my code: def g(y,x): y0 = y[0] y1 = y[1] y2 = (6*x-8)*y0/(3*x-1)+(3*x+2)*y1/(3*x-1) return [y1,y2] init = [2.0, 3.0] x=np.linspace(-2,2,100) sol=spi.odeint(g,init,x) plt.plot(x,sol[:,0]) plt.show() but what I get is different from the answer. what have I done wrong? 回答1: There are several things wrong here. Firstly, your

Taylor Method ODE

淺唱寂寞╮ 提交于 2020-01-06 02:36:08
问题 I am trying to implement the Taylor method for ODEs in MatLab: My code (so far) looks like this... function [x,y] = TaylorEDO(f, a, b, n, y0) % syms t % x = sym('x(t)'); % x(t) % f = (t^2)*x+x*(1-x); h = (b - a)/n; fprime = diff(f); f2prime = diff(fprime); y(0) = y0, for i=1:n T((i-1)*h, y(i-1), n) = double(f((i-1)*h, y(i-1)))+(h/2)*fprime((i-1)*h, y(i-1)) y(i+1) = w(i) + h*T(t(i), y(i), n); I was trying to use symbolic variables, but I don´t know if/when I have to use double. I also tried