How to plot a function is equal to a constant?

11 ビュー (過去 30 日間)
John
John 2014 年 9 月 11 日
回答済み: John 2014 年 9 月 11 日
I am new to MATLAB and am trying to graph ln(x^2)=0.7 to find the roots graphically. I have tried to following.
x=-5:5;
y=log(x.^2)-0.7;
plot (x,y)
this gets me close but the graph isn't coming out right. I also tried to y=log(x.^2)=0.7 or y=log(x.^2)-0.7=0 but this doesn't work either. Any help is appreciated!

採用された回答

Roger Stafford
Roger Stafford 2014 年 9 月 11 日
The range for x = -5:5 includes the value x = 0 for which log(0) is minus infinity. I would suggest
x = linspace(1,2,1000);
y = log(x.^2)-.7;
plot(x,y)
Look for where it crosses y = 0.
Of course there is a much easier method:
x = sqrt(exp(0.7));

その他の回答 (1 件)

John
John 2014 年 9 月 11 日
I got it to work by using ezplot('(log(x.^2)-0.7)'). Thank you though!

カテゴリ

Help Center および File ExchangeLine Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by