Can I construct a matrix multiplying a scalar and a vector?

조회 수: 4 (최근 30일)
I have a scalar i=3 and a vector j=[4; 5]. I want to generate the matrix k=[3 4; 3 5].
Is there a way to multiply i and j to generate the matrix k?

채택된 답변

Jan
Jan 2019년 9월 11일
편집: Jan 2019년 9월 11일
No, tis is not a standard multiplication. But you can create k based on i and j:
i = 3;
j = [4; 5];
% Solution 1:
k(:, 2) = j;
k(:, 1) = i;
% Solution 2:
k = i .* [1, 0; 1, 0] + j .* [0, 1; 0, 1]; % Auto-expanding, need Matlab >= R2016b
What is the general case? Why do you want a "multiplication"? Which is the problem you want to solve actually?
  댓글 수: 1
Jaime De La Mota Sanchis
Jaime De La Mota Sanchis 2019년 9월 11일
This is my current code. I am trying to construct a Smolyak collocation matrix. This general case is the construction of two rows of said matrix. If you are curious, this is the code I am using.
close all
clear
clc
contador=1;
number_of_rv=2;
mat_index = ones(number_of_rv+1, number_of_rv);
mat_ampl = zeros(2*number_of_rv+1, number_of_rv);
longitud_mat_ampl=length(mat_ampl);
for i=2: number_of_rv+1
mat_index(i,contador)=2;
contador=contador+1;
end
matriz_rv_1_ejemplo= -1*[7 8 9; 0 10 11; 0 0 12];
matriz_rv_2_ejemplo= -1*[1 2 3; 0 4 5; 0 0 6];
matriz_rvs=cat(3,matriz_rv_1_ejemplo, matriz_rv_2_ejemplo);
for i=1: number_of_rv+1
vector_indices=mat_index(i,:);
nodes_1=matriz_rv_1_ejemplo(1:vector_indices(1), vector_indices(1))
nodes_2=matriz_rv_2_ejemplo(1:vector_indices(2), vector_indices(2))
end

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by