Options for output of solve function with sequential variables
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Taylor Powell
le 13 Juil 2020
Commenté : Taylor Powell
le 14 Juil 2020
Ladies and Gents,
I'm working on a code which checks the order of a polynomial and then creates that number (n=order + 1) of unknown variables. I then create a system of n linear equations and solve them using the solve function.
My current issue is being able to output the results to a 'n' variable array and THEN access the variables in a for loop for substitution. I have a 1xn symbolic array, but when I attempt to equate solve to it, it ignores the array and creates a struct.
syms t
S = sym('S', [1 (order+1)]);
A = sym('A', [1 (order+1)]);
lhs=(myequationoft1); %These are symbolic equations my code generates
rhs=(myequationoft2); %Each is a function of symbolics t and S1,S2,...SN
eqns=sym(zeros(order+1,1)); %Creates symbolic array which I can assign the equations to...
for i=1:(order+1)
eqns(i)=(subs(diff(lhs,(i-1)),t,0)==subs(diff(rhs,(i-1)),t,0));
%Assigns the (i-1)th derivative of each equation evaluated at t=0 to eqns(i)
end
A=solve(eqns,S); %This is my issue.... Straight assignment creates a struct
%I want to be able to access the items (A.S1,A.S2,...A.SN) in a for loop
0 commentaires
Réponse acceptée
Walter Roberson
le 14 Juil 2020
fn = fieldnames(A) ;
for n=1:length(fn)
An = A.(fn{n});
do something
end
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Number Theory dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!