How to plot square root of a function?

I tried plotting the square root of an function. I expect the plot to be curved, but I get a straight line. What am I doing wrong?
x1 = 0:1:10;
y = sqrt(1-(x1).^2);
plot(x,y)

 採用された回答

VBBV
VBBV 2022 年 6 月 3 日

0 投票

x1 = 0:0.01:10; % check with small intervals
y = sqrt(1-(x1).^2);
plot(x1,real(y)); ylim([-1 1.5])
If you use small intervals for input to function, you can get a curved plot, Is this what you want ?

その他の回答 (1 件)

Steven Lord
Steven Lord 2022 年 6 月 3 日

0 投票

Your first two lines define and use a variable x1 but your third uses a variable named x that is not defined in your code. What is the definition of x?

カテゴリ

ヘルプ センター および File Exchange2-D and 3-D Plots についてさらに検索

製品

タグ

質問済み:

2022 年 6 月 3 日

回答済み:

2022 年 6 月 3 日

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by