필터 지우기
필터 지우기

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

조회 수: 1 (최근 30일)
Morgan F
Morgan F 2022년 7월 9일
답변: Sayan 2023년 9월 7일
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
Dyuman Joshi 2022년 7월 9일
편집: Dyuman Joshi 2022년 7월 9일
Are you attempting to save function handles in a matrix?
Jan
Jan 2022년 7월 10일
The function handles do not use "x" as input. So what is x?

댓글을 달려면 로그인하십시오.

답변 (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