How do i complete this matrix that has n+1 rows and m columns?
2 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
采纳的回答
per isakson
2014-11-17
编辑:per isakson
2014-11-17
"stops at the 2nd row of the matrix"   Firstly, I think it stop at the third row. Why shouldn't it stop after assigning values to three rows? I have indicated with  |<< n >>|   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 个评论
per isakson
2014-11-17
编辑:per isakson
2014-11-17
"how did you know what to put for the input vectors"   I just picked some small numbers. The row,   bk = b_vec(k + 1);,   requires that   b_vec   is at least one element larger than   a_vec.
"going on with "left quantity" and "right quantity"?"   I cannot guess. You should know what this code is supposed to do.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Data Import and Analysis 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!