如何解决如何修复我的代码以查找第二个订单 LTI?
当我运行此代码时,它会检索一个奇怪的符号,该符号应该是数学部分的答案。我尝试了值 a=1 b=4 c=40 并且它没有检索到正确的答案。有人能告诉我我做错了什么吗?我仔细检查了数学,我很确定数学部分是有序的。
//Project by Abigail Alvarado
//Question 1
#include <stdio.h>
#include <math.h>
int main()
{
//declaring variables
float a,b,c; //These will be used in the quadratic equation that will give us lambda 1 and 2
float d,root1,root2; //d is the quadratic equation determinant.
float real,img;
float y,theta;
int t;
t = 0;
d = (b * b) - (4*a*c);
/*D=d/dt or lambda; (y(0) and y'(0); ax^2 + bx + c = 0 */
//Asking for user input of coefficients
printf("Enter the values for a,and c separated by a space: ");
scanf("%f %f %f",&a,&b,&c);
if(d < 0) //if d is less than 0; the roots are complex and different.
{
real = (-b/(2*a));
img = sqrt(-d)/(2*a);
printf("Roots are complex conjugates.\n");
printf("Roots of quadratic equation are: \n Root1 = %.3f+%.3fi \n Root2 = %.3f-%.3fi",real,img,img);
}
else if(d==0) //if d==0; the roots are real and equal.
{
root1 = root2 = real;
printf("Roots are repeating real numbers.\n");
printf("Roots of the quadratic equation are: \n %.3f \n %.3%f",root2);
}
else if(d > 0) //if d is greater than 0; the roots are real and different.
{
real = (-b/(2*a));
root1 = real + (sqrt(d)/(2*a));
root2 = real - (sqrt(d)/(2*a));
printf("Roots are non-repeating real numbers.\n");
printf("Roots of quadratic equation are: \nRoot 1: %.3f \nRoot 2: %.3f ",root2);
}
//Asking user input of initial conditions; y(0)=? y'(0)=?
float i1,i2; //initial conditions
printf("\nEnter two initial conditions separated by a space (y(0) and y'(0)): ");
scanf("%f %f",&i1,&i2);
//using initial conditions to find C and theta
//Since t is equal to 0; e raised to (zero * any number) is equal to 1.
printf("\nUsing the first initial condition,C is equal to %.3f / (%.3f * theta). ",i1,(cos(img)));
printf("\nUsing the second initial condition,i2,(cos(img)));
return (0);
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。