필터 지우기
필터 지우기

Use index in anonymous function

조회 수: 1 (최근 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 CenterFile Exchange에서 Assumptions에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by