Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

I need to be able to use a vector as an input to a function either as a variable or in form [ 1 2 ...N]

조회 수: 1 (최근 30일)
I need to be able to use a vector as an input to a function, but it can be either in vector form or as a variable name: here c0 and x are scalars. C and [1 2 3] are the vectors. They need to be interchangeable in the function as inputs. q = pmath(c0, C, x) or q = pmath(c0,[1 2 3],x) either way needs to work. Can this be done? finally I need to be able to produce p = c0 +c(1)x^1 + c(2)x^2+...c(n)x^n , can I do this with:
n = linspace(1,n,n);
c0 + sum(c(:).*x.^n(:));
?
Thank you. Hope its a little clearer with this statement.
  댓글 수: 9
Image Analyst
Image Analyst 2016년 11월 28일
And do you plan on attaching capture.jpg? Insert it with the green and brown image frame icon.
Walter Roberson
Walter Roberson 2016년 11월 28일
One reason that it could skip past your breakpoints is if the function you are inserting breakpoints into is not the same function that you are running. You should check with
which -all poly_val
and make sure that the first one is the same file you are editing.

답변 (1개)

Tamir Suliman
Tamir Suliman 2016년 11월 27일
편집: Tamir Suliman 2016년 11월 27일
why dont u declare c as a vector and then c0 = c(1) c1=c(2) etc because the eqaution is on the form of c0*x^0 +c1*x^1 etc so the power of x follows c
check this link about polynomials https://www.mathworks.com/help/matlab/ref/poly.html
  댓글 수: 1
DJ V
DJ V 2016년 11월 27일
The referenced web page is all about eigenvalues and characteristic polynomials which have nothing to do with my problem. Is it possible to response with the proper form of the Matlab code to accomplish the stated goal?

태그

Community Treasure Hunt

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

Start Hunting!

Translated by