MATLAB: Plot y^2 = x^2 + 1 (The expression to the left of the equals sign is not a valid target for an assignment.)

plot hyperbolic x y 2d

%Clear memory
clear;
%Number of points
N = 10000;
%Preallocate memory
x = zeros(1,N);
y1 = zeros(1,N);
x = -5 + (5+5)*rand(1,N);
y1^2 = x^2 + 1;
plot(x,y1), grid on;
I get the following error:
The expression to the left of the equals sign is not a valid target for an assignment.
How can I plot this first on x,y axis, then on x^2 and y^2?
Thanks in advance.

Best Answer

clear all
clc;
N = 10000;
x = zeros(1,N);
y1 = zeros(1,N);
y2 = zeros(1,N);
x = -5 + (5+5)*rand(1,N);
for i=1:N
y1(i)=(x(i)^2 + 1)^(1/2);
y2(i)=-(x(i)^2 + 1)^(1/2);
end
plot(x,y1)
hold on
plot(x,y2)
grid on
good luck