Error when using ODE45

조회 수: 6 (최근 30일)
Westin Messer
Westin Messer 2018년 3월 7일
편집: Westin Messer 2018년 3월 7일
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