Question regarding solving differential equations

[EDIT: 20110607 20:45 CDT - reformat - WDR]
Hi,
I am a novice with differential equations in matlab.
I have two differential equations of the form:
i'=Ay+B
x''=C((i/x)^2)+D
A, B, C, and D are constants of specified values.
A=-10^5
B=10^4
C=2.5*10^-5
D=-10
The code which I wrote was:
function xprime = odetest(t,x)
xprime(1) = A*x(1)+B;
xprime(2) = x(2);
xprime(3) = C*((x(1)/x(3).^2))+D;
xprime = xprime(:) ;
t0 = 0; % Start time;
tf = 0.001% Stop time;
x0 = [0 0 0] % Initial conditions
[t,s] = ode23(@odetest,[t0,tf],x0);
i = s(:,1);
y = s(:,2);
x = s(:,3);
figure(1);
plot(x);
figure(2);
plot(i);
figure(3);
plot(y);
However, I am getting no plot when I try to plot x and y.
Please tell me where I am going wrong.
Also, I have another set of differential equations:
i'=-(10^5)*i
x''=200*i-4*(10^5)*x
The code is:
function xprime = odetest1(t,x)
xprime(1) = -(10.^5)*x(1);
xprime(2) = x(3);
xprime(3) = 200*x(1)-4*(10.^5)*x(3);
xprime = xprime(:) ;
t0 = 0; % Start time
tf = 0.001% Stop time
x0 = [0 0 0] % Initial conditions
[t,s] = ode23(@odetest1,[t0,tf],x0);
i = s(:,1);
y = s(:,2);
x = s(:,3);
figure(1);
plot(x);
figure(2);
plot(i);
figure(3);
plot(y);
Again, this time, all the values of i, x, and y become equal to zero.
Can you please provide me with the proper codes for these two problems?
Thanks in advance!
Debarati.

Answers (1)

I am going to interpret the first set of equations as
diff(i(t), t) = A*y(t)+B
diff(diff(x(t), t), t) = C*i(t)^2/x(t)^2+D
If that is the case, then there are not enough conditions to find the three functions i(t), x(t), and y(t) simultaneously.
Note that in your first section of code you wrote
xprime(3) = C*((x(1)/x(3).^2))+D;
That involves an unsquared numerator divided by a squared denominator, but your written equation involves a numerator divided by a denominator and the entire result squared.
I am not very familiar with ode45, but it appears to me that you are not taking in to account that your second equation involves the double-differential of x. I could be wrong on this point, though.
Your second set of equations does have an actual solution, but one involving three arbitrary constants of integration. All three of the constants of integration are multiplied by non-trivial functions of t, so they cannot simply be zeroed or otherwise ignored. Your choice of initial conditions for the functions will have substantial effect. In particular, your choice of 0 for the initial conditions forces two of the three constants to be 0, requiring i(t) to be 0 and effectively removing two of the three terms of x(t), transforming it in to a straight sin() formula.

Categories

Find more on Numerical Integration and Differential Equations in Help Center and File Exchange

Asked:

on 8 Jun 2011

Community Treasure Hunt

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

Start Hunting!