How do I create a matlab function using polyder that not only gives the coefficients but also gives the equation

whyamiincollege

whyamiincollege (view profile)

님이 질문을 제출함. 29 Apr 2019
최근 활동 madhan ravi

madhan ravi (view profile)

님이 편집함. 12 May 2019
gonzalo Mier

gonzalo Mier (view profile)

님이 답변을 채택함.
My code so far (doesnt work):
function derivativecoefficient = derivpolycalc()
a = input('Enter the coefficent of the polynomial')
x == x
n = input('Enter the power of each x')
derivativecoefficient = polyder(a)
derivative = derivativecoefficient*x^(n - 1)
end
If i just do it where it shows the coeeficents, I could simply do:
function derivativecoefficient = derivpolycalc()
a = input('Enter the coefficent of the polynomial')
derivativecoefficient = polyder(a)
>> derivpolycalc
Enter the coefficent of the polynomial[3,2,5]
a =
3 2 5
derivativecoefficient =
6 2
ans =
6 2
BUT I want a code that will display
6x^2+2x+0..
or maybe it could display
6x^5+2x^3+0
depending on what the original function was.

로그인 to comment.

R2018b

답변 수: 1

Answer by gonzalo Mier

gonzalo Mier (view profile)

on 29 Apr 2019
Edited by madhan ravi

madhan ravi (view profile)

on 12 May 2019

I think you need here the function poly2sym:

표시 이전 댓글 수: 1
gonzalo Mier

gonzalo Mier (view profile)

on 29 Apr 2019
As easy as:
p = poly2sym(derivativecoefficient)
For 6x^2+2x+0 solution, you need derivativecoefficient to be [6 2 0], meanwhile if you need the solution 6x^5+2x^3+0, it will be [6 0 2 0 0 0].
Each value correspont to a coefficient of the full polynomial, and the ones that are nulls are equal to 0
whyamiincollege

on 29 Apr 2019
Thanks!
gonzalo Mier

gonzalo Mier (view profile)

on 12 May 2019
Accept the answer if it worked for you! :)

로그인 to comment.