How can I solve an ode problem when I have in my differential equation a time series imported?
2 views (last 30 days)
Show older comments
Hello I am a new user of Matlab and I have to solve the following problem. I have the equation x''+2*ws*j*x'+ws^2*x=-F (1) I have already solved the problem when F=Asin(W*t) with both analytical and numerical solutions and they are equal. My professor asked me to estimate the function F in excel and then import this data in Matlab and solve again the equation (1) in this way in order to check if it works. I have written two codes that both give me the same results but these results are not the same with thes ones I got when I had F=Asin(Wt) in my code.
I wrote these codes
IF YOU CANNOT CHECK THE CODES PLEASE JUST ANSWER IF IT IS POSSIBLE TO IMPORT TIME SERIES IN ODE AND IN WHICH WAY! Thank you in advance!!!
1st
function f=anal()
%This script will give us the analytical solution of the linear oscillator
%equation : x''+ 2*ξ*ω*x'+ ω^2*x=0.3*g*sin(Ω*t)
R=1;
g=9.81;
ws=sqrt(3*pi*g/8*R);
A=0.3*g;
js=0.05;
w=5;
f=dsolve('D2x+2*0.05*sqrt(3*pi*9.81/8)*Dx+(3*pi*9.81/8)*x=ft','x(0)=0','Dx(0)=0','t')
F=inline(f,'t','ft');
Fdd=zeros(181,1);
Fdd=xlsread('xronoseira1.xls');
t=[0:0.05:9];
final=zeros(181,1);
for i=1:181
final(i)=F(t(i),Fdd(i));
end
final
end
2nd
function [t, q]=anal1()
tspan=[0:0.05:9];
y0=[0 0];
w=5;
R=1;
f=zeros(181,1);
f=xlsread('xronoseira1.xls');
Q=zeros(181,2);
for i=1:size(f)
fd=f(i);
[t,q]=ode45(@(t,q)simple(t,q,fd),tspan,y0);
Q(i,1)=q(i,1);
Q(i,2)=q(i,2);
end
disp(Q)
plot(t,q)
disp([t,q])
function dqdt=simple(t,q,fd)
g=9.81;
js=0.05;
ws=sqrt(3*pi*g/8*R);
A=0.3*g;
dqdt(1)=q(2);
dqdt(2)=-(2*ws*js*q(2)+ ws^2*q(1)-fd);
dqdt=dqdt';
end
end
0 Comments
Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!