Help with using the contour function with differential equations
Help with using the contour function with differential equations
(OP)
Hi,
I am trying to draw several solutions to a different equation. I have the following in MATLAB
>>eqn = 'Dy = (-exp(y))/((t*exp(y) - sin(y)))';
>>dsolve(eqn, 't')
Warning: Explicit solution could not be found; implicit solution returned.
> In dsolve at 312
ans =
t+exp(-y)*cos(y)-exp(-y)*C1 = 0
>>f = @(t, y) (-t)/(exp(-y)*cos(y)-exp(-y)); (solved for C1)
>>[T, Y] = meshgrid(-1:0.1:4, 0:0.1:3); (ranges were given)
>>contour(T, Y, f(T, Y), 30, 'k')
When I do the last contour instruction however, I get an error saying:
"??? Error using ==> mtimes
Inner matrix dimensions must agree."
I tried switching around ranges but I don't see what's wrong with the commands I have.
Any help or ideas is appreciated.
Thanks,
Aditya
I am trying to draw several solutions to a different equation. I have the following in MATLAB
>>eqn = 'Dy = (-exp(y))/((t*exp(y) - sin(y)))';
>>dsolve(eqn, 't')
Warning: Explicit solution could not be found; implicit solution returned.
> In dsolve at 312
ans =
t+exp(-y)*cos(y)-exp(-y)*C1 = 0
>>f = @(t, y) (-t)/(exp(-y)*cos(y)-exp(-y)); (solved for C1)
>>[T, Y] = meshgrid(-1:0.1:4, 0:0.1:3); (ranges were given)
>>contour(T, Y, f(T, Y), 30, 'k')
When I do the last contour instruction however, I get an error saying:
"??? Error using ==> mtimes
Inner matrix dimensions must agree."
I tried switching around ranges but I don't see what's wrong with the commands I have.
Any help or ideas is appreciated.
Thanks,
Aditya





RE: Help with using the contour function with differential equations
f = @(t, y) (-t)/(exp(-y)*cos(y)-exp(-y)); (solved for C1)
looks like you are attempting matrix / and * instead of maybe point by point. Try ./ and .* instead.
RE: Help with using the contour function with differential equations
Warning: Divide by zero.
> In @(t, y) (-t)./(exp(-y).*cos(y)-exp(-y))
??? Error using ==> contourc
Contour levels must be finite.
Warning: Error occurred while evaluating listener callback.
> In contour at 66
I am guessing it doesn't like the dividing by zero and then goes downhill from there?
Any ideas?
Thanks,
Aditya
RE: Help with using the contour function with differential equations
The eps hack:
f = @(t, y) (-t)/(eps+exp(-y)*cos(y)-exp(-y));
RE: Help with using the contour function with differential equations
Thanks,
Aditya
RE: Help with using the contour function with differential equations
Thanks a lot,
Aditya
RE: Help with using the contour function with differential equations
See the sinc.m file for an example. MATLAB does a test for the same reason and avoids the eps hack.