Matlab y^2=x^2+;1号地块。(等号左侧的表达式不是有效的赋值目标。)
我得到以下错误:Matlab y^2=x^2+;1号地块。(等号左侧的表达式不是有效的赋值目标。),matlab,function,plot,2d,Matlab,Function,Plot,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; 如何先在x、y轴上绘制,然后在x^2和y^2上绘制 提前感谢。您的功能是。如果你求解y1,你将得到一个+/-平方根的解。因此,您必须将函数分成两部分
%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;
如何先在x、y轴上绘制,然后在x^2和y^2上绘制
提前感谢。您的功能是。如果你求解y1,你将得到一个+/-平方根的解。因此,您必须将函数分成两部分,并绘制每个分支。有些人还建议使用,这很方便,但没有那么灵活:
The expression to the left of the equals sign is not a valid target for an assignment.
另一个答案给出了使用ezplot的解决方案,这是一种可以接受的方法。我想加入我的,旨在纠正你的错误:
ezplot('y1^2 = x^2 + 1')
Matlab不是一个符号方程求解器。如果要绘制
y^2=x^2+1
的解,需要找到一种方法将其表示为函数(或一组参数函数)。
%Clear memory
clear;
%Number of points
N = 10000;
x = -5:0.01:5; %This creates a vector from -5 to 5 with an interval of 0.01.
y1 = sqrt(x.^2 + 1); %Since you want to solve the equation y^2=x^2+1, one of the solution is the positive root of x^2+1 and the other is the negative.
plot(x,y1); %Plots positive root
hold on;
plot(x,-y1), grid on; %Plots negative root