sum calculation in matlab
3 views (last 30 days)
Show older comments
Hi, I have problem starting calculation of this sum
SUM(ZnSn-aSnSn+bSnTn)=0
Sum(ZnTn-aSnTn+bTnTn)=0
So I have S1 S2 S3 Z1 Z2 Z3 T1 T2 T3
I need to calculate a and b. I kinda can do it on paper by the point is to see how matlab calculate it. It should go like
Z1S1-aS1S1+bS1T1 + Z2S2-aS2S2+bS2T2 + Z3S3-aS3S3+b32T3=0
Z1T1-aS1T1+bT1T1 + Z1T1-aS1T1+bT1T1 +Z1T1-aS1T1+bT1T1 =0
How should I start it, I m super new at matlab. Should I use sum , and set a and b as vector of 0 ? Any help much appreciated
0 Comments
Answers (2)
Star Strider
on 19 Nov 2017
Note that ‘32T3’ is not a valid MATLAB variable name (they cannot begin with numbers). I changed it to ‘S2T3’, and used the Symbolic Math Toolbox:
syms a b Z1S1 S1S1 S1T1 Z2S2 S2S2 S2T2 Z3S3 S3S3 S2T3 Z1T1 T1T1
Eqns = [Z1S1-a*S1S1+b*S1T1 + Z2S2-a*S2S2+b*S2T2 + Z3S3-a*S3S3+b*S2T3 == ...
Z1T1-a*S1T1+b*T1T1 + Z1T1-a*S1T1+b*T1T1 +Z1T1-a*S1T1+b*T1T1];
[a,b] = solve(Eqns, [a b])
to produce:
a =
(S1T1*Z1T1 + S2T2*Z1T1 + S2T3*Z1T1 - T1T1*Z1S1 - T1T1*Z2S2 - T1T1*Z3S3)/(S1T1*S2T2 + S1T1*S2T3 - S1S1*T1T1 - S2S2*T1T1 - S3S3*T1T1 + S1T1^2)
b =
(S1S1*Z1T1 - S1T1*Z1S1 + S2S2*Z1T1 - S1T1*Z2S2 + S3S3*Z1T1 - S1T1*Z3S3)/(S1T1*S2T2 + S1T1*S2T3 - S1S1*T1T1 - S2S2*T1T1 - S3S3*T1T1 + S1T1^2)
I have no idea if these will produce usable results, since I do not know what any of the variables are (scalars, matrices, ...).
2 Comments
Star Strider
on 21 Nov 2017
You do not need to use the Symbolic Math Toolbox. I used it to solve for ‘a’ and ‘b’, so all you need to do is to use the equations I provided, with your numeric variables, to find the parameter values.
Torsten
on 21 Nov 2017
If you define Z, S, T as numerical arrays, you can determine a and b as
A = [-sum(S.*S) sum(S.*T);-sum(S.*T) sum(T.*T)];
rhs = [-sum(Z.*S);-sum(Z.*T)];
x = A\rhs;
a = x(1);
b = x(2);
a
b
Best wishes
Torsten.
0 Comments
See Also
Categories
Find more on Symbolic Math Toolbox 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!