How to solve second diffrential equation that look like this ?
1 view (last 30 days)
Show older comments
I am trying to solve this equation using matlab and couple others. but I do not know why it does not work.
d2y(t)/t + 2*dy(t)/t +y(t) = d2x(t)
I use this code:
t = (0:0.01:20)';
unitstep = t>=0;
syms y(t) x(t);
x(t)= (cos(t)+sin(2*t))*unitstep;
%second order diffrintial equation
sodeq = diff(y(t),2) + 2*diff(y(t)) + y(t) == diff(x(t),2);
Y = dsolve(sodeq,diff(y(t))==0,y(t)==3);
Error msg:
Error using sym/cat>checkDimensions (line 74)
CAT arguments dimensions are not consistent.
Error in sym/cat>catMany (line 37)
[resz, ranges] = checkDimensions(sz,dim);
Error in sym/cat (line 26)
ySym = catMany(dim, strs);
Error in sym/horzcat (line 19)
ySym = cat(2,args{:});
Error in dsolve>mupadDsolve (line 310)
sys_sym = [sys{~chars}];
Error in dsolve (line 189)
sol = mupadDsolve(args, options);
Error in t1 (line 17)
Y = dsolve(sodeq,diff(y(t))==0,y(t)==3);
which I do not know what it means?
0 Comments
Answers (2)
Walter Roberson
on 4 Oct 2018
Edited: Walter Roberson
on 5 Oct 2018
You defined
t = (0:0.01:20)';
unitstep = t>=0;
so after that, unitstep is a vector of length 2001, not a formula or function.
Then you do
syms y(t) x(t);
That is equivalent to
t = sym('t');
y = symfun( sym('y(t)'), t);
x = symfun( sym('x(t)'), t);
Notice it overwrites t, so afterwards t refers to a symbolic scalar, not a numeric vector.
Then you have
x(t)= (cos(t)+sin(2*t))*unitstep;
which is equivalent to
x = symfun( (cos(t)+sin(2*t))*unitstep, t);
With t now being symbolic scalar, the (cos(t)+sin(2*t)) becomes a symbolic expression. But remember that unitstep is a numeric vector, not a formula or function, so you are multiplying the (cos(t)+sin(2*t)) by that numeric vector of length 2001, giving a symbolic vector of length 2001 . So for any given t, x(t) will return a vector of length 2001.
sodeq = diff(y(t),2) + 2*diff(y(t)) + y(t) == diff(x(t),2);
y(t) is symbolic so there is no problem taking diff() of it, so the left side of that resolves to a symbolic expression. The right hand side is taking the derivative of that vector of length 2001, and so is going to give you a vector of length 2001, so sodeq is going to end up creating a vector of length 2001 of comparisons.
Y = dsolve(sodeq,diff(y(t))==0,y(t)==3);
the internal code constructing the system of equations is not expecting vectors of that size.
... In other words, you should change
t = (0:0.01:20)';
unitstep = t>=0;
to
syms t
unitstep(t) = piecewise(t>=0, 1, 0);
syms y(t) x(t)
x(t)= (cos(t)+sin(2*t))*unitstep;
sodeq = diff(y(t),2) + 2*diff(y(t)) + y(t) == diff(x(t),2);
Y = dsolve(sodeq,diff(y(t))==0,y(t)==3);
This will promptly fail complaining about the number of equations being wrong compared to the number of variables.
To get further, you need to recognize that y(t)==3 is a definition for y(t) that can be substituted into sodeq and diff(y(t))==0 . Substituting into sodeq gives you
3 == piecewise(0 < t, - 4*sin(2*t) - cos(t), 0)
This is independent of y, but has the potential to solve for t:
exact_t = solve(subs(sodeq,y,3));
approx_t = double(exact_t);
So the solution of the system of equations is y(t) == 3 (which you gave) and t is about 11.53 to solve the x portion.
See Also
Categories
Find more on Equation Solving in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!