Simple question: How to find the 'x' at a certain value of y(x) equation?

조회 수: 233 (최근 30일)
A
A 2016년 2월 28일
댓글: Star Strider 2024년 4월 17일 13:16
This may be a simple question. But let's assume I have one ugly equation:
x = [0:10];
y = @(x) x.^2.*12./23./23.9.*log(x).^2
How do I find the value of 'x' where y = 30?
Thanks!
  댓글 수: 4
Dyuman Joshi
Dyuman Joshi 2023년 10월 11일
이동: Sam Chak 2023년 10월 11일
Did you tried the approach that is mentioned in the accepted answer?
Sam Chak
Sam Chak 2023년 10월 11일
@Ceylin, Which intersection do you want to solve for x?
syms f(x)
f(x) = sin(x);
fplot(f, [-2*pi, 2*pi]), grid on % draw left side of Eqn
yline(0.2, 'r-') % draw right side of Eqn
xlabel('x')
legend('sin(x)', '0.2')

댓글을 달려면 로그인하십시오.

채택된 답변

Star Strider
Star Strider 2016년 2월 28일
This works:
x_for_y30 = fzero(@(x)y(x)-30, 50)
x_for_y30 =
14.0341
  댓글 수: 8
Thanh Thuy Duyen Nguyen
Thanh Thuy Duyen Nguyen 2024년 4월 17일 12:46
If I have x and want y then how could I compute that?
Star Strider
Star Strider 2024년 4월 17일 13:16
Actually there is an additional way of solving this, using interp1, especially if the actual function is not available —
x = [0:15]+eps;
y = @(x) x.^2.*12./23./23.9.*log(x).^2
y = function_handle with value:
@(x)x.^2.*12./23./23.9.*log(x).^2
yq = 30;
x_for_y30 = interp1(y(x), x, yq) % Get 'x' For Specific 'y'
x_for_y30 = 14.0322
y_for_x2pi = interp1(x, y(x), 2*pi) % Get 'y' For Specific 'x'
y_for_x2pi = 2.9555
figure
plot(x, y(x))
grid
hold on
plot(x_for_y30, 30, 'ms', 'MarkerFaceColor','m')
plot(2*pi, y_for_x2pi, 'cs', 'MarkerFaceColor','c')
hold off
xline(2*pi,'--k', '2\pi')
yline(y_for_x2pi, '--k', sprintf('y=%.2f for x=2\\pi',y_for_x2pi))
xline(x_for_y30, '--k', sprintf('x=%.2f for y=30',x_for_y30))
.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

John BG
John BG 2016년 2월 28일
편집: John BG 2016년 2월 29일
Alpha
If you plot the following
x=[-100:.1:100]
f = @(x) x.^2.*12./23./23.9.*log(x).^2
y=f(x)
plot(x,y)
grid on
place the marker on the point that shows y=30 f(x) is not symmetric, it has 2 zeros, and f=30 on 2 places:
x01=14.04
x02=-29.5
if what you really mean is:
f2 = @(x) x.^2.*12./(23.*23.9).*log(abs(x)).^2
then the function is symmetric and there are 2 values of x that satisfy your question:
x01=14.04
x02=-14.04
Compare both functions and y=30
If you find this answer of any help solving this question, please click on the thumbs-up vote link
thanks in advance
John

카테고리

Help CenterFile Exchange에서 Calculus에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by