How do i complete this matrix that has n+1 rows and m columns?

조회 수: 1 (최근 30일)
cakey
cakey 2014년 11월 16일
편집: per isakson 2014년 11월 17일
This stops at the 2nd row of the matrix, How can i get the whole matrix? Also, can someone explain what is going on?
function phi_values = phi_part1(a_vec, b_vec, x_vec)
n = length(a_vec);
m = length(x_vec);
phi_values = zeros(n + 1, m);
phi_values(1, :) = 1 / sqrt(b_vec(1));
a0 = a_vec(1);
b1 = b_vec(2);
phi_values(2, :) = ((x_vec - a0) .* phi_values(1, :)) / sqrt(b1);
k = 2;
%%phi_values(k + 1, :)
bk = b_vec(k + 1);
bk_minus_1 = b_vec(k);
ak_minus_1 = a_vec(k);
left_quantity = ((x_vec - ak_minus_1) .* phi_values(k, :));
right_quantity = sqrt(bk_minus_1) * phi_values(k - 1, :);
phi_values(k + 1, :) = (left_quantity - right_quantity) / sqrt(bk);
end

채택된 답변

per isakson
per isakson 2014년 11월 17일
편집: per isakson 2014년 11월 17일
"stops at the 2nd row of the matrix" &nbsp Firstly, I think it stop at the third row. Why shouldn't it stop after assigning values to three rows? I have indicated with &nbsp|<< n >>| &nbsp the rows, which do these tree assignments.
Secondly, I have added a for-loop, guessed regarding the input values and invoked the function
a_vec = randi( [1,9], [1,8] );
b_vec = randi( [1,6], [1,9] );
x_vec = randi( [1,9], [1,4] );
phi_values = cssm( a_vec, b_vec, x_vec )
phi_values =
0.4472 0.4472 0.4472 0.4472
-0.3162 -0.3162 0 0.3162
-0.6455 -0.6455 -0.2582 0.3873
2.0656 2.0656 0.2582 -0.7746
5.1430 5.1430 0.8944 -2.9069
3.8730 3.8730 1.2910 -5.9386
2.9445 2.9445 2.1939 -13.6832
1.3943 1.3943 3.6148 -30.7773
-7.6133 -7.6133 -8.5810 43.3979
where
function phi_values = cssm( a_vec, b_vec, x_vec )
n = length(a_vec);
m = length(x_vec);
phi_values = zeros(n + 1, m);
phi_values(1, :) = 1 / sqrt(b_vec(1)); % << 1 >>
a0 = a_vec(1);
b1 = b_vec(2);
phi_values(2, :) = ((x_vec - a0) .* phi_values(1, :)) ...
/ sqrt(b1); % << 2 >>
for k = 2 : n;
%%phi_values(k + 1, :)
bk = b_vec(k + 1);
bk_minus_1 = b_vec(k);
ak_minus_1 = a_vec(k);
left_quantity = ((x_vec - ak_minus_1) .* phi_values(k, :));
right_quantity = sqrt(bk_minus_1) * phi_values(k - 1, :);
phi_values(k + 1, :) ...
= (left_quantity - right_quantity) / sqrt(bk); % << 3 >>
end
end
  댓글 수: 2
cakey
cakey 2014년 11월 17일
Oh, so I had to create a loop then? Also, how did you know what to put for the input vectors? In addition, can you tell me what is going on with "left quantity" and "right quantity"? What are they calculating?
per isakson
per isakson 2014년 11월 17일
편집: per isakson 2014년 11월 17일
"how did you know what to put for the input vectors" &nbsp I just picked some small numbers. The row, &nbsp bk&nbsp=&nbspb_vec(k + 1);, &nbsp requires that &nbsp b_vec &nbsp is at least one element larger than &nbsp a_vec.
"going on with "left quantity" and "right quantity"?" &nbsp I cannot guess. You should know what this code is supposed to do.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Data Import and Analysis에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by