i cannot find all x values from abs(x) using solve() function

조회 수: 2 (최근 30일)
VISHNU PADMAKUMAR
VISHNU PADMAKUMAR 2021년 9월 30일
댓글: VISHNU PADMAKUMAR 2021년 10월 4일
syms x
y=abs(x);
r=solve(y==1,x);
ans=
r = 1
but x can be 1 as well as -1,why doesnt they show -1 as well

답변 (1개)

Steven Lord
Steven Lord 2021년 9월 30일
Tell solve to show you the parameterized solution and the conditions that those parameters need to satisfy in order for the parameterized solution to be valid.
syms x
y=abs(x);
r=solve(y==1,x, 'ReturnConditions', true)
r = struct with fields:
x: exp(y*2i) parameters: y conditions: y <= pi & 0 <= y
x isn't the set [1, -1]. But that's because there are complex solutions.
yy = exp(1i/2) % This is r.x with parameter y = 1/4
yy = 0.8776 + 0.4794i
abs(yy)
ans = 1
Or if you only want real solutions tell solve that:
r=solve(y==1,x, 'ReturnConditions', true, 'Real', true)
r = struct with fields:
x: [2×1 sym] parameters: [1×0 sym] conditions: [2×1 sym]
r.x
ans = 

카테고리

Help CenterFile Exchange에서 Formula Manipulation and Simplification에 대해 자세히 알아보기

태그

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by