Use index in anonymous function

6 次查看(过去 30 天)
Hi guys
can i include index in anonymous function for example something like this where T is matrix element. And can i call it in for loop for example:
syms T n m
delta_x=(1/50);delta_t=0.001;
x=0:delta_x:1;
t=0:delta_t:0.25;
Lamda=((delta_t)/((delta_x)^2));
n=1:length(t);m=2:length(x);k=1;
Tem=@(T,n,m)((-Lamda*T(n+1,m-1))+(2*(1+Lamda)*T(n+1,m))-(Lamda*T(n+1,m+1)))....
-((Lamda*T(n,m-1)) +(2*(1-Lamda)*T(n,m)) +(Lamda*T(n,m+1)));
for n=1:length(t)-1
for m=2:length(x)
if n==1
T(n,m)=250;
elseif m==1 && n>=2
T(n,m)=350;
else
Temp{1}=Tem(T,n,m); % I want to generate several equations from thie line
end
end
end
Best Regards,

采纳的回答

Walter Roberson
Walter Roberson 2013-10-3
Yes, it is legal to index a symbol in an anonymous function. It is recommended, however, to initialize the symbol as a matrix.
e.g.,
A = sym('A',dim)
where
dim: Integer or vector of two integers specifying dimensions of A. For example, if dim is a vector [m n], then the syntax A = sym('A',[m n]) creates an m-by-n matrix of symbolic variables. If dim is an integer n, then the syntax A = sym('A',n) creates a square n-by-n matrix of symbolic variables.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Assumptions 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by