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

Matt J
Matt J 2019년 2월 26일
inside a rather large while loop,
Your code shows a for-loop, not a while loop.

댓글을 달려면 로그인하십시오.

 채택된 답변

Matt J
Matt J 2019년 2월 26일
편집: Matt J 2019년 2월 26일

1 개 추천

If a solution exists, it has the analytical form,
x_intct=(x_3+x_5)/2;
y_intct=(y_3+y_5)/2;
alpha=atan2((y_intct-y_3)/burn_back, (x_intct-x_3)/burn_back);
beta=alpha+pi;
Instead of looping, you could just vectorize the above.

추가 답변 (0개)

카테고리

질문:

2019년 2월 26일

댓글:

2019년 2월 26일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by