int main() { char s[100]; double a, b; struct complex C1, C2; printf("Введите комплексное число в формате a, b: "); scanf("%lf%lf", &a, &b); C1 = cRead(a, b); cPrint(C1); printf("Введите комплексное число в формате a,b: "); scanf("%lf%lf", &a, &b); C2 = cRead(a,b); cPrint(C2); printf("Сумма: "); cPrint(cAdd(C1, C2)); printf("Разность: "); cPrint(cSub(C1, C2)); printf("Произведение: "); cPrint(cMul(C1, C2)); printf("Частное: "); cPrint(cDiv(C1, C2)); printf("Модуль 1-ого: %f: \n", cAbs(C1)); printf("Аргумент 1-ого: %f: \n", cArg(C1)); printf("Сопряжённое 1-ого: "); cPrint(cConj(C1)); printf("Re 1-ого: %f: \n", cReal(C1)); printf("Im 1-ого: %f: \n", cImag(C1)); return 0; }
int identical(FIELD** rm,ulong n1,ulong n2) { ulong i,j; for(j=0;j<n1;j++) //col { for(i=j;i<n1&&rm[i][j]==0;i++) ; if(i==n1) return cFALSE; //singular matrix else if(i!=j) //make rm[j][j] nonzero { FIELD* temp=rm[i]; rm[i]=rm[j]; rm[j]=temp; } cDiv(rm[j],n2,rm[j][j]); //make rm[j][j]=1 for(i=0;i<n1;i++) //make rm[i][j]=0 (i!=j) { if(rm[i][j]==0||i==j) continue; cMulvAdd(rm[i],rm[j],n2,gfsub(0,rm[i][j])); } } return cTRUE; }
void TForm1::compute_spring_forces() { double curtime = g_timer.GetTime(); if (g_last_iteration_time < 0) { g_last_iteration_time = curtime; return; } double elapsed = curtime - g_last_iteration_time; g_last_iteration_time = curtime; unsigned int i; // Clear the force that's applied to each ball for(i=0; i<m_active_balls.size(); i++) { m_active_balls[i]->current_force.set(0,0,0); } if (simulationOn) { CBall* b = m_active_balls[0]; cVector3d old_p = b->getPos(); b->setPos(tool->m_deviceGlobalPos); b->m_velocity = cDiv(elapsed,cSub(b->getPos(),old_p)); } // Compute the current length of each spring and apply forces // on each mass accordingly for(i=0; i<m_active_springs.size(); i++) { CSpring* s = m_active_springs[i]; double d = cDistance(s->m_endpoint_1->getPos(),s->m_endpoint_2->getPos()); s->m_current_length = d; // This spring's deviation from its rest length // // (positive deviation -> spring is too long) double x = s->m_current_length - s->m_rest_length; // Apply a force to ball 1 that pulls it toward ball 2 // when the spring is too long cVector3d f1 = cMul(s->m_spring_constant*x*1.0, cSub(s->m_endpoint_2->getPos(),s->m_endpoint_1->getPos())); s->m_endpoint_1->current_force.add(f1); // Add the opposite force to ball 2 s->m_endpoint_2->current_force.add(cMul(-1.0,f1)); } // Update velocities and positions based on forces for(i=0; i<m_active_balls.size(); i++) { CBall* b = m_active_balls[i]; // Certain forces don't get applied to the "haptic ball" // when haptics are enabled... if (simulationOn == 0 || i != 0) { cVector3d f_damping = cMul(DAMPING_CONSTANT,b->m_velocity); b->current_force.add(f_damping); } cVector3d f_gravity(0,GRAVITY_CONSTANT*b->m_mass,0); b->current_force.add(f_gravity); cVector3d p = b->getPos(); if (p.y - b->m_radius < FLOOR_Y_POSITION) { double penetration = FLOOR_Y_POSITION - (p.y - b->m_radius); b->current_force.add(0,m_floor_spring_constant*penetration,0); } cVector3d f_floor(0,0,0); cVector3d a = cDiv(b->m_mass,b->current_force); b->m_velocity.add(cMul(elapsed,a)); // We handle the 0th ball specially when haptics is enabled if (simulationOn == 0 || i != 0) { p.add(cMul(elapsed,b->m_velocity)); b->setPos(p); } } // Set the haptic force appropriately to reflect the force // applied to ball 0 m_haptic_force = cMul(HAPTIC_FORCE_CONSTANT,m_active_balls[0]->current_force); }