Entering calculated values for a_(ij) into matrix form.
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
Dyuman Joshi
il 9 Lug 2022
Modificato: Dyuman Joshi
il 9 Lug 2022
Are you attempting to save function handles in a matrix?
Risposte (1)
Sayan
il 7 Set 2023
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 Commenti
Vedere anche
Categorie
Scopri di più su Number Theory in Help Center e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!