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

  • MATLAB
  • Thread starter robax25
  • Start date
  • Tags
    Function
In summary, the code provided is attempting to plot the function y=x^(2/3), but is running into issues with negative values of x. The code has been corrected to only plot the real part of the function and the issue with the comma in line 2 has been identified as the cause of the problem.
  • #1
robax25
238
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
  • #2
What is your question? What result do you get when try what you wrote?
 
  • #3
Matlab does not display right graph. I think that it displays wrong. my question is that how do I print y=x.^(2/3)?
 
  • #4
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##?
 
  • #5
yes
 
  • #6
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:
  • #7
comma in line 2, not a semi-colon... that is why is was crapping out
 

1. What is the function of x^2/3 in mathematics?

The function of x^2/3 is to raise any given number, x, to the power of 2/3 or to find the square root of x^2.

2. How do you print x^2/3 using a simple function?

To print x^2/3 using a simple function, you can use the following code:
print(x**(2/3))

3. Can you explain the steps involved in printing x^2/3 using a simple function?

First, you need to declare the value of x. Then, use the exponent operator (** or ^) to raise x to the power of 2/3. Finally, use the print function to display the result.

4. Are there any limitations to using a simple function to print x^2/3?

Yes, a simple function may not be able to print x^2/3 if the value of x is a negative number. This is because raising a negative number to a fractional power results in an imaginary number which cannot be printed.

5. How can I modify the code to print x^2/3 for negative values of x?

To print x^2/3 for negative values of x, you can use the complex number function in Python. The code will look like this:
print(complex(x)**(2/3))
This will return the complex number equivalent of x^2/3.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
128
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
13
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
561
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
993
  • MATLAB, Maple, Mathematica, LaTeX
Replies
11
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
2K
Back
Top