フィルターのクリア

Accessing function output for different values of variable

2 ビュー (過去 30 日間)
Sandeep Parameshwara
Sandeep Parameshwara 2019 年 12 月 21 日
コメント済み: Sandeep Parameshwara 2019 年 12 月 22 日
This question could be very basic (in which case please refer me to relevent guide/tutorial to study), however I am stuck. My code is something like this:
P=@(rho) P0 + P1*sin(rho) + P2*cos(rho);
Q=@(rho) Q0 + Q1*sin(rho) + Q2*cos(rho);
Later, P and Q are solved and co-efficients are stored. Then I use them in
rho_grid= -1:0.1:1
for i=1:length(rho_grid)
rho=rho_grid(i);
Rq= @(rho) chol(value(Q(rho)),'upper');
Rp= @(rho) chol(value(P(rho)),'lower');
pro=@(rho) Rq(rho)*Rp(rho);
[U,S,V] = svd(pro(rho));
end
Please notice that only final values are being stored in U,S and V. I want to access U(rho), V(rho) and S(rho). How can I achieve that?
I tried using something like
[U,S,V] = @(rho) svd(pro(rho));
to which Matlab shows error "Only functions can return multiple values."

採用された回答

Walter Roberson
Walter Roberson 2019 年 12 月 22 日
rho_grid= -1:0.1:1;
Nrho = length(rho_grid);
for i = Nrho : -1 : 1 %backwards! For pre-allocation reasons
rho = rho_grid(i);
Rq = @(rho) chol(value(Q(rho)),'upper');
Rp = @(rho) chol(value(P(rho)),'lower');
pro = @(rho) Rq(rho)*Rp(rho);
[Uvals(:,:,i), Svals(:,:,i), Vvals(:,:,i)] = svd(pro(rho));
end
U = @(rho) Uvals(:,:,interp1(rho_grid, 1:Nrho, rho, 'nearest'));
S = @(rho) Svals(:,:,interp1(rho_grid, 1:Nrho, rho, 'nearest'));
V = @(rho) Vvals(:,:,interp1(rho_grid, 1:Nrho, rho, 'nearest'));
Instead of using 'nearest' in computing the index, you could go for something more sophisticated such as determining the mixing between the two closest values, and doing a weighted calculation to interpolate at the rho.
  1 件のコメント
Sandeep Parameshwara
Sandeep Parameshwara 2019 年 12 月 22 日
Thanks a lot, this is excatly what I needed. Now onwards, I will use the interpolation functions like you demonstreted.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

製品


リリース

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by