differential-equations

Error encountered while specifying events in deSolve R package

◇◆丶佛笑我妖孽 提交于 2019-12-13 03:23:39
问题 Here is the sample R code: library(deSolve) d = c(5.29,4.16,2.49,1.53,0.7,0.41,0.21)*10^-4 rho = rep(1.27,7) dg = d * sqrt(1/rho) r0 = dg/2 Fr = c(0.188,0.297,0.274,0.181,0.032,0.013,0.015) X0 = Fr*200*10^-6 N0 = X0*(3/(4*3.14*r0^3*rho)) state <- c(X1=X0[1],X2=X0[2],X3=X0[3],X4=X0[4],X5=X0[5], X6=X0[6],X7=X0[7],S=0) parameters <- c(D=6.19*60*10^-6,rho=rho,N=N0,Cs=17*10^-6,V=1000) times <- seq(0,16,by=0.0005) func2 <- function(t,state,parameters){ n <- length(state) v <- 1:(n-1) grad <- rep(NA

solve second order ODE in MATLAB/SIMULINK

自闭症网瘾萝莉.ら 提交于 2019-12-12 21:37:50
问题 I don't know how to solve this second order ODE in SIMULINK: I rewrote it to the system of first order ODEs: then giving My SIMULINK blocks are here: giving this Scope: This is the plot of symbolic solution from dsolve : It looks like the functions (plots) from symbolic and SIMULINK are little similar. 回答1: The solution was found by Phil Goddard . His answer in comments: In Simulink you are plotting y_dot, while the symbolic solution is a plot of y. So the problem was that Scope was plotting

Matlab - solving a third order differential equation

一笑奈何 提交于 2019-12-12 10:41:38
问题 y''' + 41y'' + 360y' + 900y = 600x' + 1200x; y(0)= 2 ; y'(0)= 1 ; y''(0) = -0.05 How can I solve this equation using the ODE45 function? I tried this: ==> function dydt=f(t,y) dydt = [y(2) ; y(3) ; -41*y(3)-360*y(2)- 900*y(1)] ==> clear all; timerange=[0 1.4]; %seconds initialvalues=[2 1 -0.05]; [t,y]=ode45(@dydt, timerange, initialvalues) plot(t,y(:,1)); But I need put the X part in the equation - I don't know how... 回答1: To use ODE45 (or similar) you need to convert the third order ODE into

scipy.integrate.odeint fails depending on time steps

拥有回忆 提交于 2019-12-12 05:48:30
问题 I use python for scientific applications, esp. for solving differential equations. I´ve already used the odeint function successfully on simple equation systems. Right now my goal is to solve a rather complex system of over 300 equations. At this point the odeint functions give me reasonable results as long as the time steps in the t-array are equal or smaller than 1e-3. But I need bigger time steps since the system has to be integrated over several thousand seconds. Bigger time steps yield

Using scilab to solve and plot differential equations

我只是一个虾纸丫 提交于 2019-12-12 04:56:20
问题 How can I solve the second order differential equation using scilab ode() function. (For example: y'' + 3y' +2y = f(x), y(0)=0, y'(0)=0) And then plot the result of function y(x). I want to use this to model the RLC-circuit signal with step-function input Here is the code I tried function y=u(t) y=(sign(t)+1)/2 endfunction L=0.001 R=10 C=0.000001 function zdot=f(t,y) zdot(1)= y(2); zdot(2)=(u(t)-y(1)-L*y(2)/R)/(L*C); endfunction y0=[0,0]; t0=0; t=0:0.00001:0.001; out=ode(y0,t0,t,f); clf();

Solving an ODE using matlab

孤者浪人 提交于 2019-12-12 04:23:44
问题 I have the following ODE: b'(t) + k16*b(t) = k15*a(t) where k15 and k16 are constants. Any idea on how to solve it? Thanks! Amit 回答1: That's a first order ODE. There's an analytical solution for it (just use an integrating factor). No integration required. http://www.math.hmc.edu/calculus/tutorials/odes/ However, if you want to solve it in MATLAB: >> k15 = 0.2; k16 = 0.3; % type your constants here >> a = @(t) t^2; % type your expression for a here >> dbdt = @(t,b) -k16*b + k15*a(t); >> tf =

Fitting differential equations: how to fit a set of data to a differential equation in R

笑着哭i 提交于 2019-12-12 03:49:13
问题 With a data set: conc <- data.frame(time = c(0.16, 0.5, 1.0, 1.5, 2.0, 2.5, 3), concentration = c(170, 122, 74, 45, 28, 17, 10)) and I would like to fit this data to the differential equation below: dC/dt= -kC where C would be the concentration, and time t in the data set. This would also give a result of k. Could anybody give me a clue how to do this in R? Thanks. 回答1: This could be a solution: require('deSolve') conc <- data.frame(time <- c(0.16, 0.5, 1.0, 1.5, 2.0, 2.5, 3), concentration <

Integrating differential equations of motion for orbit in Runge Kutta in C

守給你的承諾、 提交于 2019-12-12 03:48:45
问题 I'm attempting to integrate the differential equations for planetary orbit using fourth order runge-kutta in C. The first equation that I attempted to integrate was for the position, dr/dt = sqrt((2/mu)*(E-(k/r)) - pow(l, 2)/(pow(mu, 2)*pow(r, 2))). The program compiles correctly but keeps on returning nan, I'm fairly new to C so I'm wondering why that could be. The source code that I'm using is the following: double rk4 ( double t0, double u0, double dt, double f ( double t, double u ) ) { /

Using “subs” Function to Evaluate Output of “dsolve” Give Extra Output in Maltab

二次信任 提交于 2019-12-11 15:16:47
问题 Introduction If you want to know the grand scheme... read the introduction. If not, Just skip down to My Problem . I have a project for my Differential Equations and Linear Algebra course where I have to use a computer algebra system to solve both linear, ordinary differential equations of the first degree with constant coefficients and a non-linear ODE with constant coefficients. I have to show this being done both analytically and numerically. My plan is to have 2 functions that make use of

How to use one value of a matrix for each time step inside ode solver

空扰寡人 提交于 2019-12-11 14:58:50
问题 I have a vector x of length N and I want to use its values for solving the differential equation: dy/dt = x - 4*y . For each step I want the ode solver function to use one value of the vector and then use the next value of the matrix for the next step. I tried doing so by declaring the vector a global variable and use it like this inside the ode solver: global x tspan = 0:0.01:10; [t,filter_coef] = ode45(@ode_filter,tspan,0); and the solving function like this: function dx = ode_filter(t,fil)