symbolic variable and assignment operator

2 visualizaciones (últimos 30 días)
yogeshwari patel
yogeshwari patel el 21 de Ag. de 2024
Comentada: Steven Lord el 21 de Ag. de 2024
syms x
syms t
b0=0.05
a3=0.1
b3=0.3;
A=(2*b3-1)/(2*a3-1)
B=(1/2)*b0*((4*a3*b3-1)/2*a3-1);
U=zeros(1,2,'sym');
V=zeros(1,2,'sym');
A=zeros(1,2,'sym');
B=zeros(1,2,'sym');
C=zeros(1,2,'sym');
D=zeros(1,2,'sym');
series1(x,t)=sym(zeros(1,1));
series2(x,t)=sym(zeros(1,1));
U(1)=0.05*(1-tanh(B*(20*(x-0.5))));
V(1)=b0*(A-tanh(B*(20*(x-0.5))))
Unable to perform assignment because the left and right sides have a different number of elements.
Error in sym/privsubsasgn (line 1168)
L_tilde2 = builtin('subsasgn',L_tilde,struct('type','()','subs',{varargin}),R_tilde);
Error in indexing (line 999)
C = privsubsasgn(L,R,inds{:});
  1 comentario
Shantanu Dixit
Shantanu Dixit el 21 de Ag. de 2024
Hi Yogeshwari, the error occurs because you're trying to assign a vector (1x2) to a single element of the symbolic array U and V.
U(1) = 0.05 * (1 - tanh(B * (20 * (x - 0.5))));
V(1)=b0*(A-tanh(B*(20*(x-0.5))));
%% results in a 1x2 vector on the right side, which cannot be assigned to a single element on the left
Also double-check your implementation as 'B' is initially defined as a symbolic variable and is later changed to a symbolic vector making the initial declaration redundant.
B=(1/2)*b0*((4*a3*b3-1)/2*a3-1);
B=zeros(1,2,'sym');

Iniciar sesión para comentar.

Respuesta aceptada

Walter Roberson
Walter Roberson el 21 de Ag. de 2024
B=zeros(1,2,'sym');
B will be a symbolic vector of size 1 x 2
U(1)=0.05*(1-tanh(B*(20*(x-0.5))));
On the right hand side, all of the symbolic vector B is used, so the right hand side will be a 1 x 2 result. But you are attempting to assign that 1 x 2 result into a single location, U(1)
  1 comentario
Steven Lord
Steven Lord el 21 de Ag. de 2024
If you'd eliminated the line of code that overwrites the scalar you'd assigned to B first with the symbolic vector, it would give you an answer. I'll leave it to you to determine if that's the answer you expected.
syms x
syms t
b0=0.05
b0 = 0.0500
a3=0.1
a3 = 0.1000
b3=0.3;
% These assign scalars to A and B
A=(2*b3-1)/(2*a3-1)
A = 0.5000
B=(1/2)*b0*((4*a3*b3-1)/2*a3-1)
B = -0.0261
U=zeros(1,2,'sym');
V=zeros(1,2,'sym');
% Commenting these two lines out (so A and B aren't overwritten) ...
% A=zeros(1,2,'sym');
% B=zeros(1,2,'sym');
C=zeros(1,2,'sym');
D=zeros(1,2,'sym');
series1(x,t)=sym(zeros(1,1));
series2(x,t)=sym(zeros(1,1));
% ... allows these two lines to work
U(1)=0.05*(1-tanh(B*(20*(x-0.5))))
U = 
V(1)=b0*(A-tanh(B*(20*(x-0.5))))
V = 

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Symbolic Variables, Expressions, Functions, and Preferences en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by