Error when using ODE45

1 次查看(过去 30 天)
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:

采纳的回答

Star Strider
Star Strider 2018-3-7
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 个评论
James Tursa
James Tursa 2018-3-7
Can you post the actual text of the problem statement?
Westin Messer
Westin Messer 2018-3-7
Yes, I have edited the question.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Ordinary Differential Equations 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by