필터 지우기
필터 지우기

symbolic variable and assignment operator

조회 수: 2 (최근 30일)
yogeshwari patel
yogeshwari patel 2024년 8월 21일
댓글: Steven Lord 2024년 8월 21일
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
Shantanu Dixit
Shantanu Dixit 2024년 8월 21일
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');

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

채택된 답변

Walter Roberson
Walter Roberson 2024년 8월 21일
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
Steven Lord
Steven Lord 2024년 8월 21일
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 = 

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Symbolic Variables, Expressions, Functions, and Preferences에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by