Can't obtain solution for the variable gamma1, what's wrong? - maple

I want to use the following code
f := sqrt(7200*8200)*10^6:
Ig := 0, 9330; Ug := 13.134:
f_gr := 10^10:
r_e := .8:
L_e := .5*10^(-9):
C_e := 2.5*10^(-12):
Cka := .4*10^(-12):
Ckp := .8*10^(-12):
L_b := .3*10^(-9):
I_0 := I*f*Ig*(cos(.4*f/f_gr)+I*sin(.4*f/f_gr))/(f_gr*gamma1):
I_e := I_0+Ig:
U_e := I_e*(r_e+I*(2*Pi*f*L_e)):
U_p := -I*(1-gamma1)*I_0/(2*Pi*f*C_e):
Uska := Ug+U_p:
Iska := I*(2*Pi*f*Cka*Uska):
Irb := I_0+Iska:
Urb := 2.8*Irb:
Uskp := Urb+Uska:
Iskp := I*(2*Pi*f*Ckp*Uskp):
Irk := Uskp/773.5:
Ib := Irb+Iskp+Irk:
Ulb := I*(2*Pi*f*L_b*Ib):
Uv := U_e+Ulb+Urb+U_p:
Ik := Ig-Iska-Iskp-Irk:
Uk := Ug-U_e:
to solve Re(Uk)*Re(Ik)+Im(Uk)*Im(Ik)=0.186 for gamma1 (I is for imaginary unit). But this doesn't work. I've tried to use brute force, assigning some numbers to gamma1 and then finding Re(Uk)*Re(Ik)+Im(Uk)*Im(Ik), but I can't obtain a number anyway. Could you help me?

Your code has an apparent mistake in the definition of Ig, to which you have assigned the expression sequence 0, 9330.
Perhaps you intended Ig:=0.9330 instead.
restart;
f := sqrt(7200*8200)*10^6:
Ig := 0.9330:
Ug := 13.134:
f_gr := 10^10:
r_e := .8:
L_e := .5*10^(-9):
C_e := 2.5*10^(-12):
Cka := .4*10^(-12):
Ckp := .8*10^(-12):
L_b := .3*10^(-9):
I_0 := I*f*Ig*(cos(.4*f/f_gr)+I*sin(.4*f/f_gr))/(f_gr*gamma1):
I_e := I_0+Ig:
U_e := I_e*(r_e+I*(2*Pi*f*L_e)):
U_p := -I*(1-gamma1)*I_0/(2*Pi*f*C_e):
Uska := Ug+U_p:
Iska := I*(2*Pi*f*Cka*Uska):
Irb := I_0+Iska:
Urb := 2.8*Irb:
Uskp := Urb+Uska:
Iskp := I*(2*Pi*f*Ckp*Uskp):
Irk := Uskp/773.5:
Ib := Irb+Iskp+Irk:
Ulb := I*(2*Pi*f*L_b*Ib):
Uv := U_e+Ulb+Urb+U_p:
Ik := Ig-Iska-Iskp-Irk:
Uk := Ug-U_e:
And now,
solve(Re(Uk)*Re(Ik)+Im(Uk)*Im(Ik)=0.186, {gamma1});
{gamma1 = -0.9296926790 - 0.6316639400 I}

Related

flowing lights in structured text

I am very new to structured text, so pardon my simple question.
I am using OpenPLC to create this simple program. I have been following the example from the link below to create flowing lights simple program with structured text. In this video, they used 5LEDs and controlled it with case statements.
However, my question is, if my program needs to turn on 100 lights, how should I change the code?
Should I use for loops? How?
https://www.youtube.com/watch?v=PXnaULHpxC8&t=25s
Yes you can use for loops etc. to make the program more "dynamic".
Unfortunately most of the PLC's don't give you dynamic access to their digital outputs. This means that at the end you will have to write code that will translate the value from array (which you will be looping through) into digital outputs.
There are a few ways to do that. First let me show how you can create chasing light for up to 16.
PROGRAM PLC_PRG
VAR
iNumOfLights : INT := 6;
fbCounter : CTU := ;
fbTicker : BLINK := (ENABLE := TRUE, TIMELOW := T#100MS, TIMEHIGH := T#1S);
wOut: WORD;
END_VAR
fbTicker();
fbCounter(CU := fbTicker.OUT, RESET := fbCounter.Q, PV := iNumOfLights);
wOut := SHL(2#0000_0000_0000_0001, fbCounter.CV);
A := wOut.0;
B := wOut.1;
C := wOut.2;
D := wOut.3;
E := wOut.4;
F := wOut.5;
G := wOut.6;
END_PROGRAM
Or if you know output address you can do it directly to outputs.
PROGRAM PLC_PRG
VAR
iNumOfLights : INT := 6;
fbCounter : CTU := ;
fbTicker : BLINK := (ENABLE := TRUE, TIMELOW := T#100MS, TIMEHIGH := T#1S);
wOut AT %QB0.1: WORD;
END_VAR
fbTicker();
fbCounter(CU := fbTicker.OUT, RESET := fbCounter.Q, PV := iNumOfLights);
wOut := SHL(2#0000_0000_0000_0001, fbCounter.CV);
END_PROGRAM
You can also change type of chasing lights by something like.
IF fbCounter.CV = 0 THEN
wOut := 0;
END_IF;
wOut := wOut OR SHL(2#0000_0000_0000_0001, fbCounter.CV);
Now what is behind this. SHl operator will move 1 to the left on set number. For example SHL(2#0000_0000_0000_0001, 3) will result in 2#0000_0000_0000_1000. So we assign it to wOut and then access individual bits by wOut.[n].

how to use count and or expression at same time golang mongodb?

hi i write this line of codes but when i try it just return when total is greater then number i gave and it just doesn't use checked . i mean i have 6 documants and 5 of them are true but it give me 6 reuslt !
checked := bson.D{{"$or", []interface{}{bson.D{{"checked", false}}, bson.D{{"checked", nil}}}}}
totalReport := bson.D{{"total", bson.D{{"$gte", config.ReportNumberToChangeNickname}}}}
totalReportAndChecked := bson.D{{"$and", []interface{}{checked, totalReport}}}
matchStage := bson.D{{"$match", totalReportAndChecked}}
groupStage := bson.D{{"$group", bson.D{{"_id", "$user_id"}, {"total", bson.D{{"$sum", 1}}}}}}
cursor, err := UserReportDb.Aggregate(ctx, mongo.Pipeline{groupStage, matchStage})
if err != nil {
fmt.Println(err)
return &mongo.Cursor{}, err
}
i found the answer thanks
cond := bson.D{{"$cond", []interface{}{"$checked", 0, 1}}}
matchStage := bson.D{{"$match", bson.D{{"$expr", bson.D{{"$gte", []interface{}{"$total", config.ReportNumberToChangeNickname}}}}}}}
groupStage := bson.D{{"$group", bson.D{{"_id", "$user_id"}, {"total", bson.D{{"$sum", cond}}}, {"value", bson.D{{"$last", "$value"}}}}}}
cursor, err := UserReportDb.Aggregate(ctx, mongo.Pipeline{groupStage, matchStage})

Delphi - Rich edit doesn't show on dynamically created form

I've dynamically created a Form in my program, and it works and shows perfectly, but the RichEdit I've also dynamically created doesn't want to show on the Form at all. How can I show the RichEdit on the Form?
Code I'm using:
procedure TfrmPuntehou.lblAbbClick(Sender: TObject);
var
frmAbb: TForm;
redAbbreviations: TRichEdit;
begin
//opens abbreviations
frmAbb := TForm.Create(nil);
redAbbreviations := TRichEdit.Create(nil);
try
with frmAbb do
begin
Width := 400;
Height := 400;
Caption := 'Abbreviations';
Position := poOwnerFormCenter;
ShowModal;
end;
with redAbbreviations do
begin
Parent := frmAbb;
Width := 300;
Height := 353;
redAbbreviations.Paragraph.TabCount := 2;
redAbbreviations.Paragraph.Tab[0] := 30;
redAbbreviations.Paragraph.Tab[1] := 60;
Lines.Add('DEV'+#9+'='+#9+'SWD Development');
Lines.Add('1660'+#9+'='+#9+'1660s');
Lines.Add('2.1'+#9+'='+#9+'2.1s');
Lines.Add('MIN'+#9+'='+#9+'Minis');
Lines.Add('SR'+#9+'='+#9+'Stockrods');
Lines.Add('PR'+#9+'='+#9+'Pinkrods');
Lines.Add('HR'+#9+'='+#9+'Hotrods');
Lines.Add('HM'+#9+'='+#9+'Heavy Metals');
Lines.Add('V8'+#9+'='+#9+'V8s');
Lines.Add('MA'+#9+'='+#9+'Midgets A');
Lines.Add('MB'+#9+'='+#9+'Midgets B');
Lines.Add('SP'+#9+'='+#9+'Sprints');
Lines.Add('CRO'+#9+'='+#9+'Crosskarts');
Lines.Add('LM'+#9+'='+#9+'Late Models');
Font.Size := 13;
end;
finally
frmAbb.Free;
end;
end;
Move the ShowModal from the initialization part of the frmAbb to the end of the code, just before the finally statement.
procedure TForm1.Button1Click(Sender: TObject);
var
frmAbb: TForm;
redAbbreviations: TRichEdit;
begin
//opens abbreviations
frmAbb := TForm.Create(nil);
try
redAbbreviations := TRichEdit.Create(frmAbb);
with frmAbb do
begin
Width := 400;
Height := 400;
Caption := 'Abbreviations';
Position := poOwnerFormCenter;
end;
with redAbbreviations do
begin
Parent := frmAbb;
Width := 300;
Height := 353;
redAbbreviations.Paragraph.TabCount := 2;
redAbbreviations.Paragraph.Tab[0] := 30;
redAbbreviations.Paragraph.Tab[1] := 60;
Lines.Add('DEV'+#9+'='+#9+'SWD Development');
Lines.Add('1660'+#9+'='+#9+'1660s');
Lines.Add('2.1'+#9+'='+#9+'2.1s');
Lines.Add('MIN'+#9+'='+#9+'Minis');
Lines.Add('SR'+#9+'='+#9+'Stockrods');
Lines.Add('PR'+#9+'='+#9+'Pinkrods');
Lines.Add('HR'+#9+'='+#9+'Hotrods');
Lines.Add('HM'+#9+'='+#9+'Heavy Metals');
Lines.Add('V8'+#9+'='+#9+'V8s');
Lines.Add('MA'+#9+'='+#9+'Midgets A');
Lines.Add('MB'+#9+'='+#9+'Midgets B');
Lines.Add('SP'+#9+'='+#9+'Sprints');
Lines.Add('CRO'+#9+'='+#9+'Crosskarts');
Lines.Add('LM'+#9+'='+#9+'Late Models');
Font.Size := 13;
end;
frmAbb.ShowModal;
finally
frmAbb.Free;
end;
end;
You forgot to make it visible:
redAbbreviations.Visible := TRUE;
And you show the form modal before setting properties to the RichEdit.
Here is the correct reformatted code:
procedure TForm1.Button1Click(Sender: TObject);
var
frmAbb : TForm;
redAbbreviations : TRichEdit;
begin
// opens abbreviations
frmAbb := TForm.Create(nil);
try
redAbbreviations := TRichEdit.Create(frmAbb);
frmAbb.Width := 400;
frmAbb.Height := 400;
frmAbb.Caption := 'Abbreviations';
frmAbb.Position := OwnerFormCenter;
redAbbreviations.Parent := frmAbb;
redAbbreviations.Width := 300;
redAbbreviations.Height := 353;
redAbbreviations.Paragraph.TabCount := 2;
redAbbreviations.Paragraph.Tab[0] := 30;
redAbbreviations.Paragraph.Tab[1] := 60;
redAbbreviations.Lines.Add('DEV'+#9+'='+#9+'SWD Development');
redAbbreviations.Lines.Add('1660'+#9+'='+#9+'1660s');
redAbbreviations.Lines.Add('2.1'+#9+'='+#9+'2.1s');
redAbbreviations.Lines.Add('MIN'+#9+'='+#9+'Minis');
redAbbreviations.Lines.Add('SR'+#9+'='+#9+'Stockrods');
redAbbreviations.Lines.Add('PR'+#9+'='+#9+'Pinkrods');
redAbbreviations.Lines.Add('HR'+#9+'='+#9+'Hotrods');
redAbbreviations.Lines.Add('HM'+#9+'='+#9+'Heavy Metals');
redAbbreviations.Lines.Add('V8'+#9+'='+#9+'V8s');
redAbbreviations.Lines.Add('MA'+#9+'='+#9+'Midgets A');
redAbbreviations.Lines.Add('MB'+#9+'='+#9+'Midgets B');
redAbbreviations.Lines.Add('SP'+#9+'='+#9+'Sprints');
redAbbreviations.Lines.Add('CRO'+#9+'='+#9+'Crosskarts');
redAbbreviations.Lines.Add('LM'+#9+'='+#9+'Late Models');
redAbbreviations.font.Size :=13;
redAbbreviations.Visible := TRUE;
frmAbb.ShowModal;
finally
frmAbb.Free;
end;
end;

FB_FileClose is only the first time busy

I'm working with TwinCAT 3 and ST to save data from a socket connection. The sockets work and parts of the saving too, but not all of it. The first array I try to save works fine. But if i want to save another one, it fails. The FB_FileClose doesn't go bBusy.
IF reset THEN // I reset the FB after it saved one array.
bSuccess := FALSE;
iError := 0;
step := 1;
reset := FALSE;
MEMSET(ADR(saveArray), 0, SIZEOF(saveArray));
RETURN;
END_IF
CASE step OF
1:
IF path = '' THEN
bSuccess := FALSE;
iError := 12;
step := 1;
END_IF
fbFileOpen.sPathName := path;
fbFileOpen.nMode := FOPEN_MODEAPPEND OR FOPEN_MODEPLUS;
fbFileOpen.bExecute := TRUE;
fbFileOpen.tTimeout := T#2S;
fbFileOpen();
step := 2;
2:
fbFileOpen(bExecute := FALSE);
IF NOT fbFileOpen.bBusy AND NOT fbFileOpen.bError THEN
step := 3;
ELSE
iError := fbFileOpen.nErrId;
END_IF
3:
fbWriteFile.hFile := fbFileOpen.hFile;
fbWriteFile.bExecute := TRUE;
fbWriteFile.pWriteBuff := ADR(saveArray);
fbWriteFile.cbWriteLen := SIZEOF(saveArray);
fbWriteFile.tTimeout := T#2S;
fbWriteFile();
step := 4;
4:
fbWriteFile(bExecute := FALSE);
IF NOT fbWriteFile.bBusy AND NOT fbWriteFile.bError THEN
step := 5;
END_IF
5:
fbCloseFile.hFile := fbFileOpen.hFile;
fbCloseFile.bExecute := TRUE;
fbCloseFile.tTimeout := T#3S;
fbCloseFile();
IF fbCloseFile.bBusy THEN //Gets suck here at the second run. And if I remove it, the FB doesn't get busy and doesn't close my hFile.
step := 6;
END_IF
6:
fbCloseFile(bExecute := FALSE);
IF NOT fbCloseFile.bBusy AND NOT fbCloseFile.bError THEN
bSuccess := TRUE;
ELSE
iError := fbCloseFile.nErrId;
END_IF
END_CASE
I also noticed that FB_FileOpen opens the same hFile two times in a row. The second one of it can't get closed from the FB_FileClose. The next run it gets a new hFile and then it can save the data. Next one it can't, and so on. What's my error in this one?
Thank you!
Found the solution by myself after a bit of hackaround. Before I set all the parameters for FB_FileOpen, FB_FileWrite and FB_FileClose I set the execute to false like this:
1:
IF path = '' THEN
bSuccess := FALSE;
iError := 12;
step := 1;
END_IF
fbFileOpen(bExecute := FALSE); // Set this to false before.
fbFileOpen.sPathName := path;
fbFileOpen.nMode := FOPEN_MODEAPPEND OR FOPEN_MODEPLUS;
fbFileOpen.bExecute := TRUE;
fbFileOpen.tTimeout := T#2S;
fbFileOpen();
step := 2;
Now it's working.

Array changes value from string to number

I'm trying to assign a hex color value to an array. This is not possible, because when I assign the value, it is changed to a number. Here is the code that does that:
settings := {myColor: "color"}
myColor := "color"
settingName := "myColor"
settingValue := "0x00FF00"
%settingName% := settingValue
settings[settingName] := settingValue
e := settings[settingName]
MsgBox %e% - %settingValue%
;Displays 65280 - 0x00FF00
I think you went wrong in the 5th code line. Variables that you define do not get % signs.
settings := {myColor: "color"}
myColor := "color"
settingName := "myColor"
settingValue := "0x00FF00"
settingName = %settingValue% ; Alternative 1
settingName := settingValue ; Alternative 2
settings[settingName] := settingValue
e := settings[settingName]
MsgBox % e " - " settings[settingName] " - " settingValue
;Displays 0x00FF00 - 0x00FF00 - 0x00FF00
ExitApp
Though I think that you want: Settings[MyColor] = 0x00FF00, you now have Settings[0x00FF00] = 0x00FF00.
settings := {myColor: "color"}
myColor := "color"
settingName := "myColor"
settingValue := "0x00FF00"
settings[settingName] := settingValue
MsgBox % settings[settingName] " - " settingValue
;Displays 0x00FF00 - 0x00FF00
ExitApp