×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Help with using the contour function with differential equations

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

RE: Help with using the contour function with differential equations

Without having trying this I have a quick observation based on the code.

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

(OP)
Well, it's sort of better now. It does SOMETHING for contour(T, Y, f(T, Y), 30, 'k'), but then errors out saying :

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

Try a hack.  It may get you close, or put a switch in you function to test for divide by zer and supply the correct answer instead.

The eps hack:
f = @(t, y) (-t)/(eps+exp(-y)*cos(y)-exp(-y));

RE: Help with using the contour function with differential equations

(OP)
The eps hack worked, but all the curves are squished to the bottom of the plot, would the switch in the function work better? ifso, how would you do this switch?

Thanks,
Aditya

RE: Help with using the contour function with differential equations

(OP)
I am sorry, I was doing something else wrong, but I really appreciate you quick help.

Thanks a lot,
Aditya

RE: Help with using the contour function with differential equations

OK.  Good.  Thanks for the kind words.  
See the sinc.m file for an example.  MATLAB does a test for the same reason and avoids the eps hack.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources