I have a function vandermonde
function c = vandermonde(x, y)
V = [x.^0 x x.^2 x.^3]
c = V \ y;
end
it works good if I give a vector x with 4 components. But how could I make it general, even if I give a vector x with 5,6 or even 15 components? so that V = [x.^0 x x.^2 x.^3 x.^4 x.^5 .... x.^14] ? with n or something like that?

 채택된 답변

Matt J
Matt J 2015년 11월 5일

1 개 추천

V=bsxfun(@power,x(:),0:n-1)

댓글 수: 3

Matt J
Matt J 2015년 11월 5일
편집: Matt J 2015년 11월 5일
Of course, I hope you are not using this as a substitute for POLYFIT.
Karim Belkhiria
Karim Belkhiria 2015년 11월 5일
thank you for your answer! It works! but we are not allowed to use bsxfun and @power. It is a homework, and we are beginners with matlab. it should be something really simple with the basics of MATLAB. Is there any other solution with "basic" commands?
Matt J
Matt J 2015년 11월 5일
Yes, perhaps. But it is your homework...

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

추가 답변 (1개)

Karim Belkhiria
Karim Belkhiria 2015년 11월 5일
편집: Karim Belkhiria 2015년 11월 5일

0 개 추천

here is the answer that I searched for:
function c = vmonde(x, y)
n = length(x);
V = ones(n);
for j = 2:n
V(:,j) = x.*V(:,j-1);
end
c = V \ y;
disp(V)
end

댓글 수: 1

I wonder if your teacher would also have accepted this
V=exp(log(x(:))*(0:n-1))

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

카테고리

도움말 센터File Exchange에서 MATLAB에 대해 자세히 알아보기

질문:

2015년 11월 5일

댓글:

2015년 11월 5일

Community Treasure Hunt

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

Start Hunting!

Translated by