Using existing arrays in workspace

7 ビュー (過去 30 日間)
Marcus Rosales
Marcus Rosales 2019 年 11 月 17 日
コメント済み: Vladimir Sovkov 2019 年 11 月 19 日
Hello,
I am currently writing some code which finds the eigenstates of a Hamiltonian, but each time I run the code I need to solve a nonlinear differential equation. The solutions of this equation are saved into an array in the workspace.
I need to trouble shoot the code constantly, so it is annoying waiting for this nonlinear equation to be solved, and I need a fairly fine mesh to get my code working properly, so I am wondering if there is a way for me to bypass the boundary value problem solver and just take the existing solution out of my work space provided it is already there?
I appreciate any help I can get!
-Marcus
*I should also add I am just commenting out the line which uses bvp4c after I get the solution in the workspace, but would like to know if there is an automatic way to do this.
  2 件のコメント
Stephen23
Stephen23 2019 年 11 月 18 日
You might find memoize useful.
Marcus Rosales
Marcus Rosales 2019 年 11 月 18 日
I believe this is what I wanted. Thank you!

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

採用された回答

Marcus Rosales
Marcus Rosales 2019 年 11 月 18 日
You might find memoize useful.

その他の回答 (2 件)

Image Analyst
Image Analyst 2019 年 11 月 17 日
Not exactly sure what you're asking, but if you want to export the data from your current workspace to some other function's workspace, one way is to write the variables to a .mat file with the save() function.

Vladimir Sovkov
Vladimir Sovkov 2019 年 11 月 18 日
A variable stored in the Matlab workspace is accessible from any Matlab script via just addressing its name. If you want it to be accessible from a Matlab function, you must declare it "global" in all the modules (the workspace and the functions).
In my undestanding, the classical eigenstate problem (including the quantum-mechanical Schrodinger equation) is linear--H*\Psi = E*\Psi,--and very many efficient methods to solve it have been developed up to now. Why are you dealing with the nonlinear differential equation?
  3 件のコメント
Marcus Rosales
Marcus Rosales 2019 年 11 月 18 日
Thanks for your response Vladimir, but I am doing exactly what you are saying: I comment out the nonlinear solver when I have the solution in my workspace.
Furthermore, I am not dealing with Schrodinger's equation, but rather a Bogolibov de Gennes Hamiltonian for an unconventional super conductor. I need to solve a differential equation which is highly nonlinear (I know the difference... and is the reasons I am using it) to find a pair density wave as well as a super conducting order parameter to sub into my BdG Hamiltonian.
Vladimir Sovkov
Vladimir Sovkov 2019 年 11 月 19 日
In order not to alter your code every time you need/don't need the differential equation solver, you can probably use the "if" construction, such as:
if ~exist('z','var') || isempty(z) % z is your precomputed solution; you can add to this "if" other conditions pointing to an incorrect solution (wrong sizes, etc.)
z = ... % your solver
end

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

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by