General > General Technical Chat
Want advice on learning programing language for electronics C or JAVA or Python
coppice:
--- Quote from: tggzzz on August 02, 2022, 02:50:13 pm ---You will not learn C (or another language) in a few weeks.
--- End quote ---
What you won't learn quickly is how to program well. If you have years of years of programming behind you, you should be able to get useful in a new language in a week.
coppice:
Most university courses teach you python these days. For small embedded systems (e.g. MCUs) C is the main language. For bigger systems a wide diversity of languages are used.
rstofer:
A few years ago, our moderator (Simon) posted a Kirchhoff mesh type problem with reactive components which leads immediately to complex numbers. The wxMaxima solution is:
--- Code: --- --> ratprint : false$
fpprintprec : 4$
eq1 : 0 = -V1 + Z1*I1 + Z4*(I1-I2) ;
eq2 : 0 = Z4*(I2-I1) + Z2*(I2-I4) + Z5*(I2-I3) ;
eq3 : 0 = Z5*(I3-I2) + Z3*I3 + V2 ;
eq4 : 0 = Z2*(I4-I2) + V3 ;
eq5 : VA = V1 - I1*Z1 ;
eq6 : VB = VA - V3 ;
eq7 : Z1 = 2 ;
eq8 : Z2 = -5*%i ;
eq9 : Z3 = 4 ;
eq10 : Z4 = -5*%i ;
eq11 : Z5 = 4*%i ;
eq12 : V1 = 120 ;
eq13 : V2 = 120*%i ;
eq14 : V3 = 14.14*%i + 14.14 ;
res : solve([eq1,eq2,eq3,eq4,eq5,eq6,eq7,eq8,eq9,eq10,eq11,eq12,eq13,eq14])$
results : expand(float(res))$
lngth : length(results[1])$
sorted : sort(results[1])$
print("")$
for i:1 thru lngth do
print(sorted[i])$
(eq1) 0=(I1-I2)*Z4+I1*Z1-V1
(eq2) 0=(I2-I3)*Z5+(I2-I1)*Z4+(I2-I4)*Z2
(eq3) 0=(I3-I2)*Z5+I3*Z3+V2
(eq4) 0=(I4-I2)*Z2+V3
(eq5) VA=V1-I1*Z1
(eq6) VB=VA-V3
(eq7) Z1=2
(eq8) Z2=-5*%i
(eq9) Z3=4
(eq10) Z4=-5*%i
(eq11) Z5=4*%i
(eq12) V1=120
(eq13) V2=120*%i
(eq14) V3=14.14*%i+14.14
/* RESULTS */
I1=16.81-22.88*%i
I2=25.96-40.15*%i
I3=18.06-22.1*%i
I4=28.79-42.98*%i
V1=120.0
V2=120.0*%i
V3=14.14*%i+14.14
VA=45.76*%i+86.38
VB=31.62*%i+72.24
Z1=2.0
Z2=-5.0*%i
Z3=4.0
Z4=-5.0*%i
Z5=4.0*%i
--- End code ---
Maxima is very popular at CERN and wxMaxima simply adds a GUI IDE. Definitely worth knowing. Amazon has a Kindle book for wxMaxima, also in paperback but the Maxima books seem to be in Spanish.
Note how we just create a bunch of equations and then stuff them all into the solve() function. Pretty slick considering the number of complex values.
Here is the MATLAB code for the same problem, it needs a little rework before it will run on Octave:
--- Code: ---format = '%s %6.3f %+6.3fj :: %6.3f@%+6.3f Degrees\n';
z1 = 2;
z2 = -5j;
z3 = 4;
z4 = -5j;
z5 = 4j;
v1 = 120;
v2 = 120j;
v3 = 14.14 + 14.14j;
syms i1 i2 i3 i4
eqn1 = -v1 + z1 * i1 + z4 * (i1 - i2) == 0;
eqn2 = z4 * (i2 - i1) + z2 * (i2 - i4) + z5 * (i2 - i3) == 0;
eqn3 = z5 * (i3 - i2) + z3 * i3 + v2 == 0;
eqn4 = z2 * (i4 - i2) + v3 == 0;
[A,B] = equationsToMatrix([eqn1,eqn2,eqn3,eqn4],[i1,i2,i3,i4]);
X = linsolve(A,B);
va = v1 - z1 * X(1);
vb = va - v3;
rx1 = real(X(1));
ix1 = imag(X(1));
theta1 = rad2deg(double(angle(X(1))));
mag1 = abs(X(1));
rx2 = real(X(2));
ix2 = imag(X(2));
theta2 = rad2deg(double(angle(X(2))));
mag2 = abs(X(2));
rx3 = real(X(3));
ix3 = imag(X(3));
theta3 = rad2deg(double(angle(X(3))));
mag3 = abs(X(3));
rx4 = real(X(4));
ix4 = imag(X(4));
theta4 = rad2deg(double(angle(X(4))));
mag4 = abs(X(4));
rxa = real(va);
ixa = imag(va);
maga = abs(va);
thetaa = rad2deg(double(angle(va)));
rxb = real(vb);
ixb = imag(vb);
magb = abs(vb);
thetab = rad2deg(double(angle(vb)));
fprintf(format,'i1:',rx1,ix1,mag1,theta1, ...
'i2:',rx2,ix2,mag2,theta2, ...
'i3:',rx3,ix3,mag3,theta3, ...
'i4:',rx4,ix4,mag4,theta4, ...
'va:',rxa,ixa,maga,thetaa, ...
'vb:',rxb,ixb,magb,thetab);
--- End code ---
And the MATLAB results:
--- Code: --->> MeshAnalysis
i1: 16.812 -22.879j :: 28.392@-53.691 Degrees
i2: 25.964 -40.154j :: 47.817@-57.114 Degrees
i3: 18.059 -22.095j :: 28.537@-50.740 Degrees
i4: 28.792 -42.982j :: 51.734@-56.184 Degrees
va: 86.376 +45.758j :: 97.748@+27.913 Degrees
vb: 72.236 +31.618j :: 78.853@+23.639 Degrees
--- End code ---
There are a number of languages more immediately applicable to EE than C and almost everything is more applicable than Java.
nctnico:
--- Quote from: coppice on August 02, 2022, 06:49:59 pm ---
--- Quote from: tggzzz on August 02, 2022, 02:50:13 pm ---You will not learn C (or another language) in a few weeks.
--- End quote ---
What you won't learn quickly is how to program well. If you have years of years of programming behind you, you should be able to get useful in a new language in a week.
--- End quote ---
I disagree. A programming language is much more than the language itself. You also need to learn how the use the libraries / modules that come with a language in order to use a programming language effectively. This can be a huge learning curve by itself.
coppice:
--- Quote from: nctnico on August 02, 2022, 07:12:25 pm ---
--- Quote from: coppice on August 02, 2022, 06:49:59 pm ---
--- Quote from: tggzzz on August 02, 2022, 02:50:13 pm ---You will not learn C (or another language) in a few weeks.
--- End quote ---
What you won't learn quickly is how to program well. If you have years of years of programming behind you, you should be able to get useful in a new language in a week.
--- End quote ---
I disagree. A programming language is much more than the language itself. You also need to learn how the use the libraries / modules that come with a language in order to use a programming language effectively. This can be a huge learning curve by itself.
--- End quote ---
I said you can be useful. Not an expert.
Navigation
[0] Message Index
[#] Next page
[*] Previous page
Go to full version