如何修复我的代码以查找第二个订单 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 (将#修改为@)