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

  • Context: MATLAB 
  • Thread starter Thread starter robax25
  • Start date Start date
  • Tags Tags
    Function
Click For Summary

Discussion Overview

The discussion revolves around how to correctly plot the function \( y = x^{2/3} \) in MATLAB, addressing issues related to the graph's output and the handling of negative values of \( x \).

Discussion Character

  • Technical explanation, Debate/contested, Homework-related

Main Points Raised

  • One participant shares their code for plotting \( y = x^{2/3} \) but reports issues with the graph output.
  • Another participant asks for clarification on the specific problem and the results obtained from the code.
  • A participant points out that \( x^{2/3} \) can be problematic for negative values of \( x \), suggesting that this may affect the graph.
  • One participant suggests using the real part of the output to avoid issues with imaginary numbers in MATLAB.
  • A later reply indicates that a syntax error (using a comma instead of a semi-colon) in the code may be causing problems.

Areas of Agreement / Disagreement

Participants express differing views on the cause of the graphing issue, with some focusing on the handling of negative values and others on potential syntax errors. The discussion remains unresolved regarding the best approach to correct the plotting issue.

Contextual Notes

Participants have not fully explored the implications of plotting complex numbers or the specific behavior of MATLAB with negative inputs for this function.

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
3K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 5 ·
Replies
5
Views
3K
Replies
5
Views
3K
  • · Replies 5 ·
Replies
5
Views
4K
  • · Replies 4 ·
Replies
4
Views
3K