How to solve equations with data stored in a cell arrays
3 ビュー (過去 30 日間)
古いコメントを表示
Hi I am trying to solve the following equation: Eqn = (a/2)*log((Rs+a)/(Rs-a))== Ind; I can solve it for individual values of Ind using the functions solve as follows:
Ind = 13;
Rs = 5;
syms a
Eqn = (a/2)*log((Rs+a)/(Rs-a))== Ind;
Sol = solve(Eqn,a);
The problem comes when Ind data are stored in a cell array cell(1,n) and each cell contains (m x n) arrays. I would like to solve the equation for the first column of the array contained at each cell and organize the solution also in a cell array where sol{i}(1:end) comes from Ind{i}(1:end,1) I have tried:
Ind = cell(1,10);
Sol = cell(1,10);
Eqn = cell(1,10);
for i = 1:10
Ind{i} = (0:3:15)';
end
Rs = 5;
for i = 1:10
syms a
Eqn{i} = (a/2)*log((Rs+a)/(Rs-a))== Ind{i}
Sol{i} = solve(Eqn{i},a);
end
But of course it does not work. I have also tried other combination and even indexing the data with two for loops taking i and j for numbering cell number and row but I just have no idea how to treat these kind of data. Thanks a lot in advance for any advice!!!
0 件のコメント
採用された回答
Star Strider
2018 年 3 月 14 日
I would simply do this:
syms a
Ind = 13;
Rs = 5;
Ind = 0:3:15;
for i = 1:numel(Ind)
Sol{i} = solve((a/2)*log((Rs+a)/(Rs-a))== Ind(i),a);
end
4 件のコメント
Star Strider
2018 年 3 月 19 日
My pleasure.
If you only want ‘Sol{1,10}’, assign it to another variable and use that in the rest of your calculations:
Result = Sol{1,10};
You might also find the ‘matlabFunction’ function helpful if you want to convert ‘Result’ into an anonymous function. You can then use it to provide numeric results in the rest of your code.
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Number Theory についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!