Error using symfun/subsref (line 203) Invalid argument at position 2.

조회 수: 15 (최근 30일)
Catalina Ramirez
Catalina Ramirez 2023년 3월 26일
답변: Paul 2023년 3월 26일
I want to create a "for" that iterates 3 times with a symbolic function and then organize a matrix whit this 3 functions. When i try to array N, i don't know how to call the positions from the cicle "for", so I'm geting the error "Error using symfun/subsref (line 203) Invalid argument at position 2. Symbolic function expected 2 input arguments but received 1", because it is reading the numbers in N(1), N(2) and N(3) as variables.
syms x y
nnodos = 3 ;
A = 9.5
A = 9.5000
a = [16
4.5
-11];
b = [-2
3
-1];
c = [-1.5
-2.;5
-4];
for i= 1:nnodos
N = symfun(((1/(2*A))*(a(i)+b(i)*x+c(i)*y)),[x y]);
end
N = [0 N(1) 0 N(2) 0 N(3) 0; 0 N(1) 0 N(2) 0 N(3)];

답변 (2개)

Torsten
Torsten 2023년 3월 26일
N(i) = symfun(((1/(2*A))*(a(i)+b(i)*x+c(i)*y)),[x y]);
instead of
N = symfun(((1/(2*A))*(a(i)+b(i)*x+c(i)*y)),[x y]);
And
N = [0 N(1) 0 N(2) 0 N(3) 0; 0 N(1) 0 N(2) 0 N(3) 0];
instead of
N = [0 N(1) 0 N(2) 0 N(3) 0; 0 N(1) 0 N(2) 0 N(3)];

Paul
Paul 2023년 3월 26일
Hi Catalina,
Need to subscript N in the foor loop to create a vector with 3 elements. Also, the final construction of N had an error, corrected below. Also, I think there was a typo in c, also corrected below
syms x y
nnodos = 3 ;
A = 9.5
A = 9.5000
a = [16
4.5
-11];
b = [-2
3
-1];
% was
% c = [-1.5
% -2.;5
% -4];
c = [-1.5
-2.5
-4];
for i= 1:nnodos
N(i) = symfun(((1/(2*A))*(a(i)+b(i)*x+c(i)*y)),[x y]);
end
N
N = 
% added an additional zero at the end of the second row so it has the same
% number of elements as the first row
N = [0 N(1) 0 N(2) 0 N(3) 0; 0 N(1) 0 N(2) 0 N(3) 0]
N = 
The for loop can be avoided, and there does not appear to be a reason to construct each element of N as a symfun becasue the final form of N is just an exression.
N =1/(2*A)*(a+b*x+c*y);
N = [0 N(1) 0 N(2) 0 N(3) 0; 0 N(1) 0 N(2) 0 N(3) 0]
N = 

카테고리

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

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by