Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Matlab Code for solving and plotting function x'(t) = 1 + t*sin(t*x)

  1. May 9, 2013 #1
    Hi everyone,

    I am trying to solve and plot the function, x'(t) = 1 + t*sin(t*x) where x(0) = 0 and t_final = 1, in order to compare this exact solution to the approximations of Euler's and Improved Euler's Method. Can anyone help me with the code in order to solve this problem, and then plot it, using Matlab?

    Thanks in advance!!
  2. jcsd
  3. May 10, 2013 #2
    Sure. Just show us the code that you have right now and the problems you are facing and we'll help.
  4. May 10, 2013 #3
    syms x y
    init = 'y(0)=0'
    dsolve('Dy = 1 + t.*sin(t*y)', 'y(0)=0', 't')

    I keep coming up with an error.
  5. May 10, 2013 #4
    There are a number of things

    You define
    sym x y

    but use x and y in your equation

    You should define
    sym y(t)

    sym y t

    In your desolve statement you should use '==' not '='

    Lastly I don't know if the ode has an explicit solution. If it does not, then matlab will still give you an warning.
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Similar Threads - Matlab Code solving Date
A Numerical solution in matlab Sep 26, 2016
I Crank-Nicholson in 2D with MATLAB May 23, 2016
2D diffusion equation, need help for matlab code. Nov 7, 2015
Matlab code Feb 17, 2013
Hello PDE - Matlab Code - help needed Jun 2, 2009