필터 지우기
필터 지우기

calculate the function in vector.

조회 수: 2 (최근 30일)
JaeSung Choi
JaeSung Choi 2017년 6월 12일
댓글: JaeSung Choi 2017년 6월 13일
I want to calculate my 'poly' function for domain of linspace(0,1,100) so I tried ---------------------------------
%make poly function
function [output] = poly(input)
output= ([input^0 input^1 input^2 input^3 input^4 input^5]*transpose([1.0000 1.0001 0.4991 0.1703 0.0349 0.0139]) )
end
----------------------------------
x = linsapce(0,1,100)
poly(x)
----------------------------------
but it doesn't work. I found that for sin(x) it does. I want to know what's different between to func. and how to solve the problem.
  댓글 수: 1
KSSV
KSSV 2017년 6월 12일
What is the input you used? You have to take care of element by element operations.

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

채택된 답변

Andrei Bobrov
Andrei Bobrov 2017년 6월 13일
편집: Andrei Bobrov 2017년 6월 13일
function [output] = AsPolyvalForJaeSung(input)
output = bsxfun(@power,input(:),0:5)*[1.0000;1.0001;0.4991;0.1703;0.0349;0.0139];
end
  댓글 수: 1
JaeSung Choi
JaeSung Choi 2017년 6월 13일
Oh my god, you exactly catched what i wanted. Thank you very much!!

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

추가 답변 (2개)

KSSV
KSSV 2017년 6월 12일
For
input = linspace(0,1,100) ;
In the line
output= ([input.^0 input.^1 input.^2 input.^3 input.^4 input.^5]*transpose([1.0000 1.0001 0.4991 0.1703 0.0349 0.0139]) )
The size of term in square braces would be 1X600 where as the term transpose i.e second term got only 6X1 terms. How you expect them to multiply? You need to rethink on your code.
  댓글 수: 1
JaeSung Choi
JaeSung Choi 2017년 6월 12일
That's what I'm in problem. I want to derive y = [poly(0) poly(0.01) ...... poly(1)] (i.e. calculate for each domain) As for 'sin' function If we take x = linspace(0,1,100) y = sin(x) then y = [sin(0) sin(0.01) sin(0.02)..... sin(1)] I want to do same for my own function

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


Torsten
Torsten 2017년 6월 12일
output= ([(input.').^0 (input.').^1 (input.').^2 (input.').^3 (input.').^4 (input.').^5]*([1.0000 1.0001 0.4991 0.1703 0.0349 0.0139]).'
Best wishes
Torsten.
  댓글 수: 2
JaeSung Choi
JaeSung Choi 2017년 6월 12일
I've already tested for the same code. Thanks for your answer but that's not what I needed.
Torsten
Torsten 2017년 6월 13일
??
According to your question, I think this is exactly what you needed.
Best wishes
Torsten.

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

카테고리

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

Community Treasure Hunt

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

Start Hunting!