Entering calculated values for a_(ij) into matrix form.
1 回表示 (過去 30 日間)
古いコメントを表示
I am attempting to transform my a_(hj) values into matrix form to have matrix A=(a_(hj)). My values for a_(hj) are calculated as below in my for loop, just not sure how to put them into a matrix.
t_0=2
k=10
syms t
syms x
F=@(t) 1-exp(-t^2)
f=@(t) diff(F,t)
for h=1:k
for j=1:k
a_hj=@(h,j) F((h*j*t_0/k)-x)*f(x)
end
end
2 件のコメント
Dyuman Joshi
2022 年 7 月 9 日
編集済み: Dyuman Joshi
2022 年 7 月 9 日
Are you attempting to save function handles in a matrix?
回答 (1 件)
Sayan
2023 年 9 月 7 日
I understand from your query that it is required to store the values of "a_hj" in a matrix. I am assuming that you need to calculate the values of "a_hj". But it is creating a function handle instead. Another observation is that the function "f" is called with the argument "x" which differentiate the output expression of function "F" with respect to "x" which results in zero every time as the expression is a function of the symbolic variable "t". The following code snippet can be referred to deal with the issue:
t_0=2;
k=10;
sym t;
sym x;
F=@(t) 1-exp(-t^2);
f=@(t) diff(F,t);
%to use the value of function f at any particular numeric value of "t" a
%new symbolic varible p(t) is created to be used in the expression of a_hj
sum p(t);
p(t)=sym(f(t));
%pre-allocate the resulting matrix where the values of a_hj need to be stored
result=zeros(k,k);
for h=1:k
for j=1:k
%now instead of x use the required function of "h" and "j"
%represented as fcn(h,j) in the expression of a_hj
a_hj=F((h*j*t_0/k)-fcn(h,j))*p(fcn(h,j));
result(h,j)=a_hj;
end
end
Further information on symbolic variable creation can be found in the following MATLAB documentation
Hope this answers the query.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Number Theory についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!