Use index in anonymous function

3 ビュー (過去 30 日間)
Abdulaziz
Abdulaziz 2013 年 10 月 3 日
回答済み: Walter Roberson 2013 年 10 月 3 日
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 Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by