Solution of spring mass system with cubic stiffness
4 次查看(过去 30 天)
显示 更早的评论
I have below equation to solve with a given time series of gaussian white noise as f(t). Here is my code but it gives dimension error between result and the initial conditions vector. Is there any idea to fix it? Here is the error message:
Error using odearguments (line 92)
@(T,Y)SPRING(T,Y,M,C,K,K2,K3,F) returns a vector of length 10001, but the length of initial conditions vector is 2. The vector returned by @(T,Y)SPRING(T,Y,M,C,K,K2,K3,F) and the initial conditions vector must have the same number of elements.
Error in ode45 (line 115)
odearguments(FcnHandlesUsed, solver_name, ode, tspan, y0, options, varargin);*
my''+cy'+ky+k2*y^2+k3*y^3=f(t)
m=1; c=1; k=10; k2=20; k3=20;
f=randn(10000,1);
tspan=[0 10000];
y0=[0;1];
function dydt=spring(t,y,m,c,k,k2,k3,f)
dydt=[y(2); (f-c*y(2)-k*y(1)-k2*y(1)^2-k3*y(1)^3)/m];
end
[t,y]=ode45(@(t,y) spring(t,y,m,c,k,k2,k3,f), tspan, y0);
0 个评论
采纳的回答
Torsten
2018-10-11
function main
m=1; c=1; k=10; k2=20; k3=20;
tspan=[0 10000];
y0=[0;1];
f=randn(10000,1);
tf = linspace(tspan(1),tspan(end),10000); % time vector at which the f-values occured
[t,y]=ode45(@(t,y) spring(t,y,m,c,k,k2,k3,tf,f), tspan, y0)
end
function dydt=spring(t,y,m,c,k,k2,k3,tf,f)
f_actual = interp1(tf,f,t);
dydt=[y(2); (f_actual-c*y(2)-k*y(1)-k2*y(1)^2-k3*y(1)^3)/m];
end
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Ordinary Differential Equations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!