Mathematica Help: Plotting y=k-x/k for All -10<k<10

  • Thread starter hang2010wang
  • Start date
  • Tags
    Mathematica
In summary, the conversation is about using Mathematica to plot a function with a range of values for k, but encountering an issue when k=0. The individual mentions trying various methods to eliminate k=0 and thanks others for their help.
  • #1
hang2010wang
2
0
Hi, Guys
Can someone help me about this question?
I am trying to use Mathematica to plot all the functions: y=k-x/k for all -10<k<10 with interval of 0.1
what I wrote is like this:
Plot[Table[k-x/k,{k,-10,10,0.1}],{x,-10,10}]

However, because the function doesn't have meaning when k=0.

So how can I type the comment to eliminate k=0
 
Mathematics news on Phys.org
  • #2
I cheated and tried this: Plot[Table[{k - x/k, -k + x/k}, {k, 1, 10, 1}], {x, -10, 10}]
 
  • #3
You could also try this:
s1=Plot[Table[k-x/k,{k,0.1,10,0.1}],{x,-10,10}]
s2=Plot[Table[k-x/k,{k,-10,-0.1,0.1}],{x,-10,10}]
Show[s1,s2]
Enjoy!
 
  • #4
HAHA,many thanks for all
I have just discovered that it's even better if type in:
Plot[Table[-x/k+k,Cases[{k,-10,10,0.1},Except[0]]],{x,-10,10}]
 
  • #5
?

I would suggest using the "ConditionalExpression" function in Mathematica to eliminate the value of k=0 in your plot. This will allow you to plot the function for all values of k except for k=0. Your code could look like this:

Plot[Table[ConditionalExpression[k-x/k, k != 0], {k, -10, 10, 0.1}], {x, -10, 10}]

This will ensure that the function is only evaluated for values of k that are not equal to 0, and will not plot any points where k=0. This will give you a more accurate representation of the function and avoid any potential errors. I hope this helps!
 

FAQ: Mathematica Help: Plotting y=k-x/k for All -10<k<10

What is the purpose of plotting y=k-x/k for all -10

The purpose of plotting this function is to visualize its behavior and identify any patterns or relationships between the variables, k and x. This can help in understanding the behavior of the function and making predictions or calculations based on the plotted data.

How do I plot this function in Mathematica?

To plot y=k-x/k for all -10

Can I customize the appearance of the plot?

Yes, you can customize the appearance of the plot by using various options in the Plot function. These options include changing the color, style, and thickness of the plotted line, adding labels and titles, and adjusting the axes and gridlines.

How can I add more curves to the plot?

You can add more curves to the plot by using the Show function. This allows you to combine multiple plots into one figure. For example, if you want to add the curve y=x to the plot of y=k-x/k, you can use the command Show[Plot[k-x/k, {k, -10, 10}], Plot[x, {k, -10, 10}]].

Is there a way to export the plot as an image or a file?

Yes, you can export the plot as an image or a file by using the Export function. This allows you to save the plot in various formats, such as PNG, JPEG, PDF, or SVG. For example, the command Export["plot.png", Plot[k-x/k, {k, -10, 10}]] will save the plot as a PNG image named "plot" in the current directory.

Similar threads

Replies
4
Views
2K
Replies
3
Views
2K
Replies
5
Views
2K
Replies
1
Views
1K
Replies
5
Views
976

Back
Top