Error when using ODE45

1 view (last 30 days)
Westin Messer
Westin Messer on 7 Mar 2018
Edited: Westin Messer on 7 Mar 2018
Hello
I'm trying to write a code to solve a system of differential equations. One of the given conditions is F(0) = f(t). However when I try and implement that in the code I get an error. I believe that's because ode45 only wants variable inputs for the conditions. How do I get around this?
p_max = 50;
t = 2; % seconds
T = 0.2; % seconds
tau = 2; % seconds
c = 5; % m/s
L = 10; % meters
h = 5;
t = linspace(1,0.2,1000);
for i=1:1000
f(i) = (5/2)*(1-cos(2*pi*t(i)/T));
end
figure(1)
plot(t,f);
syms x y z
% t = x
% r = y
% p = z
F = @(t,x) [x(2); ((c^2)*(100/h^2)) - (1/tau)*x(2)];
[t,xa] = ode45(F,[0 20],[f 0]);
figure(2)
plot(t,xa(:,2))
title('y(t)')
xlabel('t'), ylabel('y')
Problem statement:
he series of the 2nd order ODE can be further reduced to a series of 1st order ODE, as shown in equation (40). The ODE system can be numerically solved with Matlab ODE45. Using the values of the parameters described in this paper, develop your matlab code to reproduce the results of Figures 2a and 2b in this paper based on the Maxwell material model.
Equation 40:
Initial Condition function:
Figures 2a and 2b:

Accepted Answer

Star Strider
Star Strider on 7 Mar 2018
What do actually want to do?
If ‘f’ is a forcing function, incorporate it with ‘t’ as an input to your differential equation, not as an initial condition.
See for example: ODE with Time-Dependent Terms (link).
  4 Comments
James Tursa
James Tursa on 7 Mar 2018
Can you post the actual text of the problem statement?
Westin Messer
Westin Messer on 7 Mar 2018
Yes, I have edited the question.

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!