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

回答(1 个)

Sayan
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.

类别

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

标签

产品

Community Treasure Hunt

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

Start Hunting!

Translated by