How to graph ln(x^2)=0.7?

35 ビュー (過去 30 日間)
sam
sam 2013 年 2 月 2 日
回答済み: Image Analyst 2022 年 12 月 5 日
I know how to graph f(x) equations in matlab but I have no idea how I would enter ln(x^2)=0.7 and have it plotted? Sorry I am very new to matlab.
  2 件のコメント
Image Analyst
Image Analyst 2013 年 2 月 2 日
What is there to plot? You can solve for x, but you have no y values to plot. You only have two isolated x values that solve the equation but you don't have any dependent variable to plot, unless you want to say y = ln(x^2) and plot that, then plot a horizontal line at y = 0.7 and observe where it intersects the first plot. Is that what you want to do?
Youssef  Khmou
Youssef Khmou 2013 年 2 月 2 日
i agree with "Image Analyst" , maybe "sam" wants to plot vertical lines as constants x1=(exp(0.5*0.7)) x2=-exp(0.5*0.7) .

サインインしてコメントする。

回答 (3 件)

Daniell Algar
Daniell Algar 2013 年 2 月 2 日
Well, to plot the point f(x)= 0.7, I guess you would need to use a solver, e.g. ode45.
To just plot the function, you first specify the x-values, then calculates the y-values, then plot them, i.e.
x= 1: .1: 100;
y= log(x.^2);
figure(1)
plot(x, y)
  2 件のコメント
Youssef  Khmou
Youssef Khmou 2013 年 2 月 2 日
Hi, the x axis above will not give the right value 0.7 .
Daniell Algar
Daniell Algar 2013 年 2 月 2 日
As I said...

サインインしてコメントする。


Youssef  Khmou
Youssef Khmou 2013 年 2 月 2 日
Hi , Sam
Using Symbolic Math ToolBox :
You define your variable x and your constant c ( in your case c=0.7) and solve your equation :
syms x c
x=solve('log(x^2)=c');
figure, ezplot(x(1)), title(' Root 1')
figure, ezplot(x(2)), title(' Root 2')
You will get
x =
exp(1/2*c)
-exp(1/2*c)
Next , as c=0.7 in your example, you compute the solution numerically :
c=0.7; root1=exp(0.5*0.7); root2=-exp(0.5*c);
figure, plot(root1,0:0.001:1), hold on ,
plot(root2,0:0.001:1,'r'), legend(' root1','root2'),
title(' Solution log(x^2)=0.7')

Image Analyst
Image Analyst 2022 年 12 月 5 日
Try this:
x = linspace(1, 2, 10000);
y = log(x.^2);
plot(x, y, 'b-', 'LineWidth', 2)
hold on;
yline(0.7, 'Color', 'r', 'LineWidth', 2)
grid on;
% Find element of y closest to 0.7
[minDistance, index] = min(abs(y - 0.7))
minDistance = 3.6143e-05
index = 4191
xCrossing = x(index)
xCrossing = 1.4190
% Put a green line there
xline(xCrossing, 'Color', 'g', 'LineWidth', 2)
yCrossing = y(index)
yCrossing = 0.7000
caption = sprintf('y crosses 0.7 at x = %f', xCrossing);
title(caption);

カテゴリ

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