Welcome Address

Only available on StudyMode
  • Download(s) : 616
  • Published : December 13, 2012
Open Document
Text Preview

A simple program to calculate quadratic equation with.Input MUST have the format:AX2 + BX + C = 0EXAMPLE: input the equation 2X2 + 4X -30 = 0 as:A= 2 B= 4 C= -30The answers for AX2 + BX + C = 0 should be 3 and -5.x1=3x2=-5 bool solver(float...

A simple program to calculate quadratic equation with.
Input MUST have the format:
AX2 + BX + C = 0
EXAMPLE: input the equation
2X2 + 4X -30 = 0 as: 
A= 2 B= 4 C= -30 
The answers for AX2 + BX + C = 0 should be 3 and -5.
x1=3
x2=-5

[pic]Collapse | Copy Code
bool solver(float a,float b, float c, float &x1, float &x2)
{
float delta = sqrt( (b*b) - (4*a*c) );
if (!a) return false;
x1 = ( -b + delta)/(2*a);
x2 = ( -b - delta)/(2*a);
return true;
}
 
int main()
{
float a=2,
b=4,
c=-30;
 
/*
printf("a = ");
scanf("%f", &a);
printf("b = ");
scanf("%f", &b);
printf("c = ");
scanf("%f", &c);
 
*/
 
float x1,x2;
if ( solver(a, b ,c, x1, x2) ) printf("x1=%f\nx2=%f\n",x1,x2);

return 0;
}

Hi!

I'm kinda new at VBA and I would need some help. I have a problem with the quadratic equation(module12.bas). I needs to count how many tries it took to get the x1 and x2 and then put them on to the sheet.

I also have a second problem concerning drawing in VBA. I would like to know how to insert trees to the sheet, so they are further away from each other(they must be so that you can separate them by looking at them), at the moment they are like 2mm apart and that is not the way they should be.

I would really appreciate the help. Thanks!
[pic]
Quadratic Equation
I have a function that takes in a value and performs some mathematical equations. In my program...I am throwing up a message box when value is below zero. My problem is this....suppose I had a graph and was plotting three points ( a line from (0,0) moving in a 45º angle up and to the right.) This would be ideal...but sometimes my values that are input by the user cause my equation to plot the first point at...lets say....(-3,3)...now the x value is negative and flags my error. I would like to make x equal to zero if x is negative. Heres my function...

Function ScaleAnalogOut(Value As Double, Chnl As Integer) As Long Dim Temp As Double, d As Double
'want to get the counts from the proposed reading.
'solve for x where y = C + Bx + Ax^2
'A,B,C are scale factors from analog.dat
'using quadratic x = (-b + sqr(b^2-4ac))/2a
'A = scalef(2) B = scalef(1) and C=scalef(0) - value
'the following was used with linear mx+b

Temp = Value
If -AIOInfo(Chnl).ScaleF(2) = 0 Then 'linear
If AIOInfo(Chnl).ScaleF(1) = 0 Then
Temp = 0
Else
Temp = (Temp - AIOInfo(Chnl).ScaleF(0)) / AIOInfo(Chnl).ScaleF(1) * &H10000 End If
Else 'parabolic
d = AIOInfo(Chnl).ScaleF(1) ^ 2 - 4 * AIOInfo(Chnl).ScaleF(2) * (AIOInfo(Chnl).ScaleF(0) - Value) If d < 0 Then
ErrorShow "Analog scale values invalid."
ElseIf d = 0 Then
Temp = -(AIOInfo(Chnl).ScaleF(1)) / (2 * AIOInfo(Chnl).ScaleF(2)) * &H10000 Else
Temp = (-AIOInfo(Chnl).ScaleF(1) + Sqr(d)) / (2 * AIOInfo(Chnl).ScaleF(2)) * &H10000 If Temp < 0 Or Temp > AIOInfo(Chnl).MaxRaw * &H10000 Then
Temp = (-AIOInfo(Chnl).ScaleF(1) - Sqr(d)) / (2 * AIOInfo(Chnl).ScaleF(2)) * &H10000 End If
End If
End If
If Temp < 0 Then '3/24/97
ErrorShow "Scaled value " & Temp & "Setting to 0." ScaleAnalogOut = 0 * &H10000
ElseIf Temp > AIOInfo(Chnl).MaxRaw * &H10000 Then
ErrorShow "Scaled value > " & AIOInfo(Chnl).MaxRaw & "." & Value & " ->" & Temp & "Setting to " & AIOInfo(Chnl).MaxRaw ScaleAnalogOut = AIOInfo(Chnl).MaxRaw * &H10000
Else
ScaleAnalogOut = Temp
End If
End Function
[pic]
Quadratic Equation Graphing
OK heres the problem ive made the quadratic equation solver... but now, is there a way to graph them like in a calculator or something? if so could you tell me how and could you be specific because im a nub programmer who has been teaching himself. Anywho here is my current code if you...
tracking img