Options for output of solve function with sequential variables
4 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Taylor Powell
am 13 Jul. 2020
Kommentiert: Taylor Powell
am 14 Jul. 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 Kommentare
Akzeptierte Antwort
Walter Roberson
am 14 Jul. 2020
fn = fieldnames(A) ;
for n=1:length(fn)
An = A.(fn{n});
do something
end
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Number Theory 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!