Different Approach to solve ODE

Hello all,
I am trying to solve an ODE but I am not sure if the approach using ode45 is right.
1st Approach:
% Quadratic damping Response
tspan = 0:1800;
y0 = [0;0];
[t,y] = ode45 (@forced,tspan,y0);
plot(t,y(:,1));
grid on
xlabel ('time(s)')
ylabel ('Displacement(m)')
title ('System Response')
hold on
% Linear Damping Response
f = 0.01; % Force (N)
c = 0.01; % Damping coefficient (N.s/m)
k = 20;
w = 2*pi; % frequency (rad/s)
m = 0.5; % Mass (Kg)
wn = sqrt(k/m); % Natural Frequency
cc = 2*m*wn; % Critical Damping
z = c/cc;
a = -(2*z*w*wn*f/m)/((wn^2 - w^2)^2 + (2*z*w*wn)^2);
b = ((wn^2 - w^2)*f/m)/((wn^2 - w^2)^2 + (2*z*w*wn)^2);
X = sqrt(a^2 + b^2);
fi = -atan(a/b);
x = X*sin(6.28*t - fi);
plot(t,x);
function yp = forced(t,y)
yp = [y(2);
0.01/0.5*cos(2*pi*t)-1/0.5*y(2)^2-20/0.5*y(1)];
end
2nd Approach
syms x(t)
Dx = diff(x);
ode = diff(x,t,2) == 0.01*cos(2*pi*t) - 2*(diff(x,t,1))^2 - 40*x;
xSol(t)= dsolve(ode);
This second approach gives me the warning that it is unable to find symbolic solution. I already have installed the symbolic toolbox but, still getting the same results.
Any help?
Thank you in Advance

 Accepted Answer

I have no idea how the ‘Linear Damping Response’ section figures into this.
However:
syms t x(t) Y
Dx = diff(x);
ode = diff(x,t,2) == 0.01*cos(2*pi*t) - 2*(diff(x,t,1))^2 - 40*x;
[VF,Sbs] = odeToVectorField(ode);
forced = matlabFunction(VF, 'Vars',{t,Y});
% Quadratic damping Response
tspan = 0:1800;
y0 = [0;0];
[t,y] = ode45 (forced,tspan,y0);
figure
plot(t,y(:,1));
grid on
xlabel ('time(s)')
ylabel ('Displacement(m)')
title ('System Response')
hold on
will do what you want with respect to integrating the symbolic expression.
The matlabFunction function creates an anonymous function version of the ODE from the vector field created by odeToVectorField. See the documentation section on Anonymous Functions for details on them and how to use them.

4 Comments

Yeah, the linear damping response I already have the equation solved. I wrote it there just to plot in the same figure.
Does the ODE that I wrote in the script is the same as this ?
Thank you !
It looks to me to be the same.
Alright, thank you so much !
My pleasure!

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!