Cell elements must be character arrays. (Solver equations created in a loop)
14 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Karen Mohammadtabar
am 8 Aug. 2020
Kommentiert: Karen Mohammadtabar
am 11 Aug. 2020
I am trying to solve a system of linear equations numerically, where I have 3 variables and 50 equations. I am creating the euations in a foor loop. here is my code:
Temps_all = [500, 550, 600, 650, 700];
Shear_cal = [0.019, 0.038, 0.058, 0.067, 0.077, 0.096, 0.115, 0.135, 0.154, 0.231];
syms ln_A delta_E delta_X
Yield = [2, 4, 12, 33, 57, 2, 6, 14, 30, 59, 2, 8, 15, 34, 59, 3, 5, ...
11, 33, 55, 7, 8, 12, 44, 58, 6, 12, 32, 44, 58, 12, 15, 36, 58, ...
68, 15, 21, 41, 58, 75, 7, 18, 42, 53, 69, 11, 23, 31, 48, 72, 3, ...
4, 13, 40, 57];
Ar = 42;
kB = 0.001985875;
C = 6.941215543; % Convergence factor
eqns_all = [];
for shear = 1:length(Shear_cal)
for temp = 1:length(Temps_all)
eqn = ln_A -(delta_E-Ar*delta_X*Shear_cal(shear))*C/(kB*Temps_all(temp))...
- log(Yield((shear-1)*length(Temps_all)+temp)) == 0;
eqns_all = [eqns_all;{eqn}];
end
end
S_all = solve(eqns_all,[ln_A delta_E delta_X]);
The euations are created and appended to the equation list eqns_all. But when I run the script I get the following error at the last line where solver is being used. I am not fimiliar with character arrays so any help is greatly appreciated.
Error using char
Cell elements must be character arrays.
Error in solve>isOption (line 459)
b = ~isa(a, 'logical') && any(strcmpi(char(a), ...
Error in solve>getEqns (line 392)
while k <= numel(argv) && ~isOption(argv{k})
Error in solve (line 226)
[eqns,vars,options] = getEqns(varargin{:});
Error in Bell (line 34)
S_all = solve(eqns_all,[ln_A delta_E delta_X]);
0 Kommentare
Akzeptierte Antwort
Walter Roberson
am 11 Aug. 2020
eqns_all = [eqns_all;{eqn}];
solve() cannot process a cell array of equations. You should leave out the {}
Weitere Antworten (1)
Surya Talluri
am 11 Aug. 2020
I understand that you want to solve a system of 50 linear equations for 3 variables. I am not able to reproduce the error on my side.
If the error is persisting, you can try solving the linear equations using “equationsToMatrix” and “linsolve” functions.
[A, B] = equationsToMatrix(eqns_all, [ln_A delta_E delta_X]);
S_all = linsolve(A,B);
You can have a look at the documentation for further understanding - https://www.mathworks.com/help/symbolic/solve-a-system-of-linear-equations.html
Siehe auch
Kategorien
Mehr zu Ordinary Differential Equations finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!