How to input y' = 2x^3 - 2xy into matlab?

1 view (last 30 days)
I input it as :
2*x.^3-2*x*y;
but it didn't work.
I also tried this:
(2*x.^3)-(2*x*y);
How can i fix this?
  2 Comments
James Tursa
James Tursa on 17 Feb 2017
Edited: James Tursa on 17 Feb 2017
Didn't work in what way? What are the sizes of x and y? In the future, please give us some context for what you are doing, and also include the actual code you are using along with an exact copy&paste of the error message you are getting.
S.R.
S.R. on 17 Feb 2017
Trying to plot a direction field.

Sign in to comment.

Accepted Answer

Walter Roberson
Walter Roberson on 17 Feb 2017
syms y(x)
sol = dsolve( diff(y,x) == 2*x.^3-2*x*y )
The output will look something like
C4*exp(-x^2) + x^2 - 1
The C4 might be a different C* name. The C* name refers to a constant whose value depends upon the unspecified boundary conditions.
  1 Comment
Walter Roberson
Walter Roberson on 17 Feb 2017
Try
2*x.^3 - 2*x.*y
if your x and y are both vectors of equal length, or are both 2D arrays that are the same size.
If you are trying to do a 2D plot, then something like
xrange = linspace(-5, 7, 50); %for example
yrange = linspace(pi, 8, 75); %for example
[X, Y] = ndgrid(xrange, yrange);
u = 2*X.^3 - 2*X.*Y;
v = 0 * u;
quiver(X, Y, u, v)

Sign in to comment.

More Answers (2)

James Tursa
James Tursa on 17 Feb 2017
Edited: James Tursa on 17 Feb 2017
Maybe this?
(2*x.^3)-(2*x.*y)
But hard to say if this is correct for you application since we don't know the sizes of x and y and how you are using this.

Muhammad syafikh Mohd umar
How to answer 3^2x.sqrt(9)=729

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!