how to create on an efficient way zeros in a symbolic matrix?

66 次查看(过去 30 天)
hey,
I want to create a matrix/array A with size(n,2) (for arbitrary n) such that
A(:,1) = zeros(n,1)
A([1:n-1],2) = 0;
A(n,2) = x (with x a symbolic, in matlab written as 'sym x' )
How do I do it on a efficient way?

采纳的回答

MA
MA 2014-11-12
编辑:MA 2014-11-12
syms x
n=4;
A=sym(zeros(n,2));
A(:,1) = zeros(n,1);
A([1:n-1],2) = 0;
A(n,2) = x;
A

更多回答(2 个)

Walter Roberson
Walter Roberson 2021-9-30
A = [zeros(n,2,'sym') ; 0, x];

Sulaymon Eshkabilov
syms x
n=4;
A=sym(zeros(n,2));
% A(:,1) = zeros(n,1); % NOT Necessary
% A([1:n-1],2) = 0; % NOT Necessary
A(n,[1,2]) = x %#OK
A = 

类别

Help CenterFile Exchange 中查找有关 Symbolic Math Toolbox 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by