Speeding up solve() function in a for loop
Ältere Kommentare anzeigen
I am trying to write a bit of code to solve for a system of 4 equations inside a rather large while loop, this leads to the solve() function being performed multiple times and drastically slows down the run time. Is there a way to preallocate the symbolically solved variables (so as to only input the new number) or is there a way to have matlab solve the system with matrices.
The code:
for d_t = 0:100
burn_back = d_t*5e-3;
x_5 = 0.0710;
x_3 = 0.4397;
y_5 = 0.5487;
y_3 = 0.3358;
syms alpha beta x_intct y_intct;
[alpha,beta,x_intct,y_intct] = solve(...
x_intct == x_3 + burn_back*cos(alpha),...
x_intct == x_5 + burn_back*cos(beta),...
y_intct == y_3 + burn_back*sin(alpha),...
y_intct == y_5 + burn_back*sin(beta),...
[alpha beta x_intct y_intct]);
alpha = double(alpha);
beta = double(beta);
x_intct = double(x_intct);
y_intct = double(y_intct);
end
Any help would be greatly apreciated.
1 Kommentar
Matt J
am 26 Feb. 2019
inside a rather large while loop,
Your code shows a for-loop, not a while loop.
Akzeptierte Antwort
Weitere Antworten (0)
Kategorien
Mehr zu Calculus finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!