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

Click For Summary

Discussion Overview

The discussion revolves around solving and plotting the differential equation x'(t) = 1 + t*sin(t*x) with the initial condition x(0) = 0, and t_final = 1. Participants are seeking assistance with Matlab code to compare the exact solution to approximations using Euler's and Improved Euler's Method.

Discussion Character

  • Technical explanation, Homework-related

Main Points Raised

  • One participant requests help with Matlab code to solve and plot the given differential equation.
  • Another participant asks for the existing code and specific problems encountered to provide assistance.
  • A participant shares a code snippet using symbolic variables and expresses difficulty due to an error message.
  • Concerns are raised about the correct definition of variables in the code, suggesting the use of 'sym y(t)' instead of 'sym y t'.
  • It is noted that the dsolve statement should use '==' instead of '=' and that there may not be an explicit solution to the ODE, which could lead to a warning from MATLAB.

Areas of Agreement / Disagreement

Participants are collaboratively working through coding issues, but there is no consensus on the existence of an explicit solution to the differential equation.

Contextual Notes

Limitations include potential misunderstandings in variable definitions and the possibility that the ODE does not have an explicit solution, which remains unresolved.

bdoherty1994
Messages
4
Reaction score
0
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!
 
Physics news on Phys.org
Sure. Just show us the code that you have right now and the problems you are facing and we'll help.
 
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.
 
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)

not
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.
 

Similar threads

  • · Replies 8 ·
Replies
8
Views
3K
  • · Replies 4 ·
Replies
4
Views
4K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 11 ·
Replies
11
Views
3K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 5 ·
Replies
5
Views
4K
  • · Replies 2 ·
Replies
2
Views
4K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 5 ·
Replies
5
Views
3K