How to plot graph y=1/x or y=x^2

3.9k Views Asked by At

I am using Octave but I think it applies to MatLab too, so I'm tagging this MatLab since there isnt a Octave tag

When I do

x=linspace(-5,5,25)
y=1/x

I get

error: operator /: nonconformant arguments (op1 is 1x1, op2 is 1x25)

Or

x=linspace(-5,5,25)
y=x^2

I get

error: for A^b, A must be square

How can I then plot the graphs of each?

1

There are 1 best solutions below

0
On BEST ANSWER

Try:

x=linspace(-5,5,25)
y = 1./x
plot(x,y)

x=linspace(-5,5,25)
y=x.^2
figure
plot(x,y)