How do i complete this matrix that has n+1 rows and m columns?
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
cakey
el 16 de Nov. de 2014
Editada: per isakson
el 17 de Nov. de 2014
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 comentarios
Respuesta aceptada
per isakson
el 17 de Nov. de 2014
Editada: per isakson
el 17 de Nov. de 2014
"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 comentarios
per isakson
el 17 de Nov. de 2014
Editada: per isakson
el 17 de Nov. de 2014
"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.
Más respuestas (0)
Ver también
Categorías
Más información sobre Data Import and Analysis en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!