MATLAB Print a Simple Function: How to Print x^2/3 in Just a Few Steps

  • Thread starter Thread starter robax25
  • Start date Start date
  • Tags Tags
    Function
Click For Summary
The discussion centers on plotting the function y = x^(2/3) in MATLAB. The initial code provided was x = -100:100; y = x.^(2/3); plot(x,y). Users pointed out that this code does not display the correct graph due to issues with negative values of x, which result in complex numbers. It was clarified that MATLAB ignores the imaginary part when plotting, leading to confusion. A suggested solution is to modify the code to y = real(x.^(2/3)) to ensure only real values are plotted. Additionally, a minor syntax correction was noted regarding the use of a comma instead of a semicolon in the second line of the code.
robax25
Messages
238
Reaction score
3
how I print x^2/3

Here is my code
Matlab:
x=-100:100;
y=x.^(2/3),
plot(x,y)
 
Physics news on Phys.org
What is your question? What result do you get when try what you wrote?
 
Matlab does not display right graph. I think that it displays wrong. my question is that how do I print y=x.^(2/3)?
 
robax25 said:
Matlab does not display right graph. I think that it displays wrong.
It is hard to help you without more details.

You do realize that ##x^{2/3}## is problematic for ##x <0##?
 
yes
 
I can't see anything wrong with your code.

Did you notice the bit where Matlab states that it ignores the imaginary part of the answer when plotting?
What you are effectively doing is this
Matlab:
x=-100:100;
y=real(x.^(2/3))   %%Real part only
plot(x,y)
 
Last edited by a moderator:
comma in line 2, not a semi-colon... that is why is was crapping out
 

Similar threads

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