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

30 visualizzazioni (ultimi 30 giorni)
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)];

Risposte (2)

Torsten
Torsten il 26 Mar 2023
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 il 26 Mar 2023
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 = 

Categorie

Scopri di più su Symbolic Math Toolbox in Help Center e File Exchange

Prodotti


Release

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by