How can I write a system of equation more fastly
2 views (last 30 days)
Show older comments
Hi, I have to write a function and this function is a big system of non linear equation but this system is repetitive. See later:
function F = funzioni(x)
global Ts0 Tgr vs Ros Cs lx h S Tg
F = [x(1)-Ts0;
x(2)-Ts0;
x(3)-Ts0;
x(4)-Ts0;
x(5)-Ts0;
x(6)-Tgr;
vs*Ros*Cs*((x(12)+x(2)-x(7))/(2*lx))-(h*S*(Tg-x(7)));
vs*Ros*Cs*((x(13)+x(3)-x(8))/(2*lx))-(h*S*(Tg-x(8)));
vs*Ros*Cs*((x(14)+x(4)-x(9))/(2*lx))-(h*S*(Tg-x(9)));
x(10)-x(9);
x(11)-Tgr;
vs*Ros*Cs*((x(17)+x(7)-x(12))/(2*lx))-(h*S*(Tg-x(12)));
vs*Ros*Cs*((x(18)+x(8)-x(13))/(2*lx))-(h*S*(Tg-x(13)));
vs*Ros*Cs*((x(19)+x(9)-x(14))/(2*lx))-(h*S*(Tg-x(14)));
x(15)-x(14);
x(16)-Tgr;
vs*Ros*Cs*((x(22)+x(17)-x(12))/(2*lx))-(h*S*(Tg-x(17)));
vs*Ros*Cs*((x(23)+x(18)-x(13))/(2*lx))-(h*S*(Tg-x(18)));
vs*Ros*Cs*((x(24)+x(19)-x(14))/(2*lx))-(h*S*(Tg-x(19)));
x(20)-x(19);
x(21)-Tgr;
vs*Ros*Cs*((x(27)+x(17)-x(22))/(2*lx))-(h*S*(Tg-x(22)));
vs*Ros*Cs*((x(28)+x(18)-x(23))/(2*lx))-(h*S*(Tg-x(23)));
vs*Ros*Cs*((x(29)+x(19)-x(24))/(2*lx))-(h*S*(Tg-x(24)));
x(25)-x(24);
x(26)-Tgr;
x(27)-x(22);
x(28)-x(23);
x(29)-x(24);
x(30)-x(29);];
how can I write this system more fastly??? thanks a lot
0 Comments
Answers (1)
Walter Roberson
on 13 Mar 2012
Write simple helper expressions.
LK1 = @(K) vs*Ros*Cs*((x(K+10)+x(K)-x(K+5))/(2*lx))-(h*S*(Tg-x(K+5)));
LK2 = @(K) vs*Ros*Cs*((x(K+5)+x(K)-x(K-5))/(2*lx))-(h*S*(Tg-x(K)));
[....
X(6)-Tgr;
LK1(2);
LK1(3);
LK1(4);
x(10)-x(9);
x(11)-Tgr;
LK1(7);
LK1(8);
LK1(9);
x(15)-x(14);
x(16)-Tgr;
LK2(17);
LK2(18);
LK2(19);
....]
See Also
Categories
Find more on Custom Message Support in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!