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

25 vues (au cours des 30 derniers jours)
Koen
Koen le 12 Nov 2014
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?

Réponse acceptée

MA
MA le 12 Nov 2014
Modifié(e) : MA le 12 Nov 2014
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

Plus de réponses (2)

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

Sulaymon Eshkabilov
Sulaymon Eshkabilov le 30 Sep 2021
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 = 
  2 commentaires
Walter Roberson
Walter Roberson le 30 Sep 2021
A(n, 1) should not be x
Sulaymon Eshkabilov
Sulaymon Eshkabilov le 30 Sep 2021
Yes, you are right. But I put A(n, [1, 2]) =x just as an example.

Connectez-vous pour commenter.

Community Treasure Hunt

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

Start Hunting!

Translated by