Borrar filtros
Borrar filtros

Entering calculated values for a_(ij) into matrix form.

1 visualización (últimos 30 días)
Morgan F
Morgan F el 9 de Jul. de 2022
Respondida: Sayan el 7 de Sept. de 2023
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 comentarios
Dyuman Joshi
Dyuman Joshi el 9 de Jul. de 2022
Editada: Dyuman Joshi el 9 de Jul. de 2022
Are you attempting to save function handles in a matrix?
Jan
Jan el 10 de Jul. de 2022
The function handles do not use "x" as input. So what is x?

Iniciar sesión para comentar.

Respuestas (1)

Sayan
Sayan el 7 de Sept. de 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.

Etiquetas

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by