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

1 view (last 30 days)
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

Accepted Answer

per isakson
per isakson on 17 Nov 2014
Edited: per isakson on 17 Nov 2014
"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 Comments
cakey
cakey on 17 Nov 2014
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 on 17 Nov 2014
Edited: per isakson on 17 Nov 2014
"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.

Sign in to comment.

More Answers (0)

Categories

Find more on Data Import and Analysis in Help Center and File Exchange

Tags

Products

Community Treasure Hunt

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

Start Hunting!