How to get to the expected result in wxMaxima - symbolic-math

The problem seems to be simple, but I don't know how to get the solution
Entered in wxMaxima
xt:xm-w/2;
z:w/(xmax-xmin+2*ma);
xa:xt/z;
x:xa+xmax/2+xmin/2;
expand(x);
-(xm*xmin)/w + xmin + (xm*xmax)/w + (2*ma*xm)/w - ma
This is OK, but we can simplify a bit deeper.
Simplified by myself
x = -(xm*xmin)/w + xmin + (xm*xmax)/w + (2*ma*xm)/w - ma
x = xm/w * (xmax-xmin + 2*ma) + xmin - ma
or
z = w/(xmax-xmin+2*ma)
So
x = xm/z + xmin - ma
Question:
Is there a possibility in wxMaxima to get this result ?
x = xm/z + xmin - ma
Thanks in advance
Christian

You can try using equations instead of variables:
(%i) remvalue(all)$
(%i) EQ1:xt=xm-w/2$
(%i) EQ2:z=w/(xmax-xmin+2*ma)$
(%i) EQ3:xa=xt/z,[EQ1,EQ2]$
(%i) EQ4:x=xa+xmax/2+xmin/2,[EQ3]$
(%i) EQ5:solve([EQ2],w)$
(%i) EQ4,[EQ5]$
(%i) expand(%);
(%o) x=xm/z+xmin-ma
for better understanding:
xa=xt/z,[EQ1,EQ2];
is the short form of:
ev(xa=xt/z,[xt=xm-w/2,z=w/(xmax-xmin+2*ma)]);

Meantime I found the other solution. Thanks :-)
xt:xm-w/2;
z:w/(xmax-xmin+2*ma);
xa:xt/z;
x:xa+xmax/2+xmin/2;
w:solve('z=z,w)[1];
x:subst(w,x);
expand(x);

Related

Why my R seems take forever to run a Mixed effects logistic regression

I indeed got a relatively big dataset and my mixed effects logistic regression is like below. Is that normal to take that long to run? or I made some mistakes?
library(lme4)
glmer_EBRD_undersample_1 <- glmer(leave_happened ~
performance_rating_2016 + performance_rating_2017 + performance_rating_2018 + performance_rating_2019 + performance_rating_2020
+ gender
+ target_group
+ target_pmf_band
+ target_hq_or_ro
+ target_office_location_country_distilled
+ target_org_unit_cost_centre_code_distilled
+ target_ebrd_region_distilled
+ target_contract_group_distilled
+ target_position_tenure_group
+ target_length_of_service_group_distilled
+ leaves_to_date
+ moves_to_date
+ joins_to_date
+ applied_count_to_date
+ line_reviewed_to_date
+ interviewed_to_date
+ offered_to_date
+ hired_to_date
+ (1 | person_id)
,
data = train_undersample_1,
family = binomial,
control = glmerControl(optimizer = "bobyqa"),
nAGQ = 10
)
summary(glmer_EBRD_undersample_1)
Also gave a warning like this: Warning in commonArgs(par, fn, control, environment()) :
maxfun < 10 * length(par)^2 is not recommended.

PowerApps Distance Between Coordinates in a Loop

I am new to PowerApps. I have a Share Point List with a set of coordinates for various locations. What I need to figure out is when a user with PowerApps App on their phone are within a certain distance of those coordinates, using the Haversine formula. While the Haversine formula works in a test/simple way using hard-coded target location, I need the target locations from the Share Point List. Here is my code, which is inside a Timer End:
ForAll(
irfan_yard_locations,
With(
{
r: 6371000, p: (Pi() / 180), latA: location_lat, lonA: location_long, latB: Location.Latitude, lonB: Location.Longitude
},
Round((2 * r) * Asin(Sqrt(0.5 - Cos((latA - latB) * p)/2 + Cos(latB * p) * Cos(latA * p) * (1 - Cos((lonA - lonB) * p)) / 2)), 2 ));
) ;
irfan_yard_locations is the SP List which has location_lat and location_long coordinates. I am thinking something like in this example site: http://powerappsguide.com/blog/post/formula-how-to-use-the-if-and-switch-functions so that if the return from the with (), which would be a number, is less than 5 (it's in meters) then Navigate to another screen or do something. Just don't know the syntax. Or is there better approach?
Thanks!
Never mind. By putting in an If clause around the With function, I am able to catch if the current location is within 6 meters of one of the coordinate sets.
ForAll(
irfan_yard_locations,
If ( With(
{
r: 6371000, p: (Pi() / 180), latA: location_lat, lonA: location_long, latB: Location.Latitude, lonB: Location.Longitude
},
Round((2 * r) * Asin(Sqrt(0.5 - Cos((latA - latB) * p)/2 + Cos(latB * p) * Cos(latA * p) * (1 - Cos((lonA - lonB) * p)) / 2)), 2 )) < 6, Navigate(Screen2));
) ;

how to create pymol rename loop

I would like to create a loop for changing interactions name in PyMol. But after one selection loop it crashes and doesn't work.
def get_dists(interactions): # interactions=([1,2], [3,4])
for i in interactions:
a = "////" + str(i[0]) + "/C2'"
b = "////" + str(i[1]) + "/C2'"
cmd.distance("(" + a + ")", "(" + b + ")")
for j in range(1, 599):
x = "dist" + "0" + str(j)
y = str(i[0]) + " " + str(i[1])
cmd.set_name(str(x), str(y))
In Pymol the default name of interactions is dist01, 02 , 03.
I want to change these to 1_3, 5_59, 4_8, (interaction between residue).
Your code is totally fine except for one thing: If PyMol doesn't succeed with set_name the whole script is aborted. When you change it to, it should work:
try:
cmd.set_name(str(x), str(y))
except:
print('failed to rename')
Some additional comments:
y = str(i[0]) + " " + str(i[1]) should be y = str(i[0]) + "_" + str(i[1])
this line is probably for padding zeros x = "dist" + "0" + str(j). This is only needed when j is a single digit, otherwise the name of the distance objects is dist20 or dist123
cmd.set_name(str(x), str(y)) can be simplified to cmd.set_name(x, y) since x and y are already strings.

AgentSpeak: Problems at sending plan (Jason)

I'm trying to send a plan from Agent1 to Agent2 via:
#c2[atomic]
+giveRule[source(A)]: planGiven(B) <-
-+planGiven(B+1);
.send(A, tellHow, "#s1 +sum(num1(X, Y), num2(A, B))[source(S)] :logic(L) & attentiveness(T)<- if ((L + T) > 2){ -+res(num1(X, Y), num2(A, B), res(X*10 + A*10 + Y + B)); .send(S, tell, result(X*10 + A*10 + Y + B)); } else { -+res(num1(X, Y), num2(A, B), res(X + A + Y + B)); .send(S, tell, result(X + A + Y + B)); }.");
-+stopGivingPlan.
Then, i'm trying to make this plan work by sending a message from Agent1 to Agent2:
#c3[atomic]
+giveProbs[source(A)]: probsGiven(B) & stud(A,X)<-
-+probsGiven(B+1);
.send(A, tell, sum(num1(3,3), num2(4,9))).
It doesn't work.
Why?
And important addition:
If I don't send plan, and just copy it in Agent2, it works fine. so Syntax is ok.
Also, i'm using jason plugin in eclipse, if that's worth to be mentioned.
It is not quite clear what is being performed, it is better if you can show the whole code. I simplified the case just to try to show a general idea, as bellow:
Agent1 code:
!start.
+!start: true <-
.send(agent2, tellHow, "#s1 +!sum(num1(X, Y), num2(A, B))[source(S)] :true <- -+res(num1(X, Y), num2(A, B), res(X + A + Y + B)); ?res(Z1,Z2,Z3); .print(Z1,\"+\",Z2,\"=\",Z3).");
.send(agent2, achieve, sum(num1(1,2), num2(3,4))).
Agent2 code:
/* No previous code - agent1 will send a plan*/
The response should be:
[agent2] num1(1,2)+num2(3,4)=res(10)
In this case, agent2 has nothing to do until agent1 sends a plan. Agent1 is also sending a triggering plan to achieve a sum.

Calculating OpenGL Face Normals of Polygon

I am trying to add lighting to a polygon created from a point polygon file. My problem is when creating vectors from the points I only get a certain section of the polygons lit, then if I inverse the calculation for normals, (From A.x - C.x to C.x - A.x) it lights the section that was not previously lit. Code and pictures below.
h_vector V1;//= (p2 - p1);
// A = 0 B = 1 C = 2 D =3
V1.x = vertices[1].x - vertices[0].x;
V1.y = vertices[1].y - vertices[0].y;
V1.z = vertices[1].z - vertices[0].z;
h_vector V2;// = (p3 - p1);
V2.x = vertices[3].x - vertices[0].x;
V2.y = vertices[3].y - vertices[0].y;
V2.z = vertices[3].z - vertices[0].z;
/*
h_vector V1;//= (p2 - p1);
V1.x = vertices[0].x - vertices[1].x;
V1.y = vertices[0].y - vertices[1].y;
V1.z = vertices[0].z - vertices[1].z;
h_vector V2;// = (p3 - p1);
V2.x = vertices[0].x - vertices[3].x;
V2.y = vertices[0].y - vertices[3].y;
V2.z = vertices[0].z - vertices[3].z;
*/
surfaceNormal.x = (V1.y*V2.z) - (V1.z-V2.y);
surfaceNormal.y = - ( (V2.z * V1.x) - (V2.x * V1.z) );
surfaceNormal.z = (V1.x-V2.y) - (V1.y-V2.x);
float normalize = sqrtf((pow(surfaceNormal.x,2) + pow(surfaceNormal.y,2) + pow(surfaceNormal.z,2)));
surfaceNormal.x = surfaceNormal.x/normalize;
surfaceNormal.y = surfaceNormal.y/normalize;
surfaceNormal.z = surfaceNormal.z/normalize;
This cross product code is badly broken:
surfaceNormal.x = (V1.y*V2.z) - (V1.z-V2.y);
surfaceNormal.y = - ( (V2.z * V1.x) - (V2.x * V1.z) );
surfaceNormal.z = (V1.x-V2.y) - (V1.y-V2.x);
The expressions within the parentheses should all have a multiplication operator, but half of them are subtractions instead in the code above.
The cross product calculation should be:
surfaceNormal.x = V1.y * V2.z - V1.z * V2.y;
surfaceNormal.y = V1.z * V2.x - V1.x * V2.z;
surfaceNormal.z = V1.x * V2.y - V1.y * V2.x;
You may want to look into using a matrix/vector library. There are many of them freely available if you do some searching.

Resources