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

$\begingroup$

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?

$\endgroup$

1 Answer

$\begingroup$

Try:

x=linspace(-5,5,25)
y = 1./x
plot(x,y)
x=linspace(-5,5,25)
y=x.^2
figure
plot(x,y)
$\endgroup$

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like