[英]Passing more variables to matrix operator in pcg - Matlab
我想使用矩陣運算符而不是矩陣在Matlab中調用函數pcg(共軛梯度)。 問題是我想傳遞給矩陣運算符的不僅僅是向量x。 我也想給它傳遞另一個變量。 我該怎么做呢?
提前致謝。
我假設您正在嘗試使用第一個輸入作為函數句柄 (即您正在調用矩陣運算符 )的函數輸入來調用函數PCG ,該函數afun
接受向量輸入X
並返回矩陣向量乘積A*X
如果您想提供其他變量來afun
除了剛才X
,你可以參數化功能,無論是使用嵌套函數或匿名函數 。 這是一個匿名函數示例:
A = [...]; %# Some matrix you want to use in your function
B = [...]; %# The other matrix to pass to PCG
afun = @(x) A*x; %# Construct an anonymous function using the current value of A
X = pcg(afun,B); %# Pass the anonymous function as the first argument
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.