필터 지우기
필터 지우기

showing roots of an equation

조회 수: 1 (최근 30일)
metin yilmaz
metin yilmaz 2020년 11월 10일
댓글: Walter Roberson 2020년 11월 10일
Would you please explain what is wrong with this operation? I entered an equation as a string and then assigned it
to a variable named d. Then I used that variable in the solve command and since there are two roots I considered d as a
struct with two fields. Is this correct? Is d a struct or not? Then I tried to show roots as fields by writing d(1) and d(2)
but the operations gave very strange results in the following.
>> d='x^2-6*x-12'
d =
'x^2-6*x-12'
>> solve(d)
ans =
3 - 21^(1/2)
21^(1/2) + 3
>> d(1)
ans =
'x'
>> d(2)
ans =
'^'
Would you also please introduce some other methods to show roots?

채택된 답변

KSSV
KSSV 2020년 11월 10일
편집: KSSV 2020년 11월 10일
Write the coefficients of your polynomial as an array ans use roots.
p = [1 -6 -12] ;
s = roots(p)
Use symbolic
syms x
p = x^2-6*x-12 ==0 ;
s = solve(p)
  댓글 수: 4
metin yilmaz
metin yilmaz 2020년 11월 10일
Okay, thank, so without introducing x as symbolic by syms, d(1) and d(2) only give the elements of the string assigned to the varible? Right?
Walter Roberson
Walter Roberson 2020년 11월 10일
solve(d)
That does not change d. You would have needed
d = solve(d)

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

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by