C PROGRAMMING HELP NEEDED! So, I've made progress on my script, but I'm having trouble making the next step in my assignment work properly. So far my script can: 1) Be prompted to type in coefficients of the Linear Systems and Two Initial Conditions. D2y+a1Dy+a2 = 0;  and 2) Find the roots of the second order nontrivial solution. D2y+a1Dy+a2 = 0 => λ 2+a1 λ +a2 = 0   But I need it to do the following: Based on the roots λ1 and λ2 of the second order system, your script should decide: a) If roots (λ’s) are nonrepeating real , the response y(t) is y(t) = C1 e λ1t+C2e λ2t, for t≥0. Find C’s and display your y(t) on screen. b) If roots (λ’s) are repeating real (λ1 =λ2), the response y(t) is y(t) = (C1 +C2te)λt, for t≥0. Find C’s and display your y(t) on screen. c) If roots (λ’s) are complex conjugate (λ’s = α+jβ and α-jβ ), the response y(t) is y(t)=Cαtcos(βt+θ), for t≥0. Find C and θ and display your y(t) on screen. Please use conditionals. Also please use user-defined functions to compute C’s and θ. Also, Please, PLEASE NO IOSTREAM.H OR CACIO.H I CANNOT USE THOSE HEADERS.    Thank you for your help! Pasted below is my script in its current state, I also attached a picture of the assingment so that it may be clearer: #include #include int main() { int a, b, c, d; double root1, root2; printf("Enter a, b and c where a*x*x + b*x + c = 0\n"); scanf("%d%d%d", &a, &b, &c); d = b*b - 4*a*c; if (d < 0) { //complex roots printf("First root = %.2lf + j%.2lf\n", -b/(double)(2*a), sqrt(-d)/(2*a)); printf("Second root = %.2lf - j%.2lf\n", -b/(double)(2*a), sqrt(-d)/(2*a)); } else { //real roots root1 = (-b + sqrt(d))/(2*a); root2 = (-b - sqrt(d))/(2*a); printf("First root = %.2lf\n",root1); printf("Second root = %.2lf\n",root2); } return 0; }

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
100%

C PROGRAMMING HELP NEEDED!

So, I've made progress on my script, but I'm having trouble making the next step in my assignment work properly.

So far my script can:

1) Be prompted to type in coefficients of the Linear Systems and Two Initial
Conditions.
D2y+a1Dy+a2 = 0; 

and

2) Find the roots of the second order nontrivial solution.
D2y+a1Dy+a2 = 0 => λ 2+a1 λ +a2 = 0

 

But I need it to do the following:

Based on the roots λ1 and λ2 of the second order system, your script should decide:


a) If roots (λ’s) are nonrepeating real , the response y(t) is
y(t) = C1 e λ1t+C2e λ2t, for t≥0.
Find C’s and display your y(t) on screen.


b) If roots (λ’s) are repeating real (λ1 =λ2), the response y(t) is
y(t) = (C1 +C2te)λt, for t≥0.
Find C’s and display your y(t) on screen.


c) If roots (λ’s) are complex conjugate (λ’s = α+jβ and α-jβ ), the response y(t) is
y(t)=Cαtcos(βt+θ), for t≥0.
Find C and θ and display your y(t) on screen.

Please use conditionals. Also please use user-defined functions to compute C’s and θ. Also, Please, PLEASE NO IOSTREAM.H OR CACIO.H I CANNOT USE THOSE HEADERS. 

 

Thank you for your help! Pasted below is my script in its current state, I also attached a picture of the assingment so that it may be clearer:

#include <stdio.h>
#include <math.h>

int main()
{
int a, b, c, d;
double root1, root2;

printf("Enter a, b and c where a*x*x + b*x + c = 0\n");
scanf("%d%d%d", &a, &b, &c);

d = b*b - 4*a*c;

if (d < 0) { //complex roots
printf("First root = %.2lf + j%.2lf\n", -b/(double)(2*a), sqrt(-d)/(2*a));
printf("Second root = %.2lf - j%.2lf\n", -b/(double)(2*a), sqrt(-d)/(2*a));
}
else { //real roots
root1 = (-b + sqrt(d))/(2*a);
root2 = (-b - sqrt(d))/(2*a);

printf("First root = %.2lf\n",root1);
printf("Second root = %.2lf\n",root2);
}

return 0;
}

3) Based on the roots ₁ and ₂ of the second order system, your script should decide
a) If roots ('s) are nonrepeating real, the response y(t) is
y(t) = C₁ e Alt+C₂e22t, for t20.
Find C's and display your y(t) on screen.
b) If roots ('s) are repeating real (^₁ =^₂), the response y(t) is
y(t) = (C₁+C₂te), for t20.
Find C's and display your y(t) on screen.
c) If roots ('s) are complex conjugate (λ's =a+jß and a-jß), the response y(t) is
y(t)=Catcos(Bt+0), for t20.
Find C and 9 and display your y(t) on screen.
For step 3, use conditionals. Also use user defined functions to compute C's and 0.
Transcribed Image Text:3) Based on the roots ₁ and ₂ of the second order system, your script should decide a) If roots ('s) are nonrepeating real, the response y(t) is y(t) = C₁ e Alt+C₂e22t, for t20. Find C's and display your y(t) on screen. b) If roots ('s) are repeating real (^₁ =^₂), the response y(t) is y(t) = (C₁+C₂te), for t20. Find C's and display your y(t) on screen. c) If roots ('s) are complex conjugate (λ's =a+jß and a-jß), the response y(t) is y(t)=Catcos(Bt+0), for t20. Find C and 9 and display your y(t) on screen. For step 3, use conditionals. Also use user defined functions to compute C's and 0.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 2 images

Blurred answer
Follow-up Questions
Read through expert solutions to related follow-up questions below.
Follow-up Question

Please create the header file as specified and implement it into my script. Thank you for your help, it is seriously appreciated! This is the last question I can post today so please answer thoroughly, I will upvote just as thoroughly!!

The header file deals with the following instruction prompt:

Find the roots of the second order nontrivial solution.
D2y+a1Dy+a2 = 0 => λ 2+a1 λ +a2 = 0
Create a header file for this step!! And this step Only!

I believe the portion of the script that needs to be turned into a utilized header file is located in the main() function. Thank you so much for your help, pasted is a copy of my script so far:

#include <stdio.h>
#include <math.h>

void compute_coefficients(double lambda1, double lambda2, double *C1, double *C2, double *C_alpha, double *theta);
void display_output(double lambda1, double lambda2, double C1, double C2, double C_alpha, double theta);

int main()
{
    int a, b, c;
    double lambda1, lambda2, C1, C2, C_alpha, theta;

    printf("Enter a, b, and c where a*D2y + b*Dy + c*y = 0:\n");
    scanf("%d%d%d", &a, &b, &c);

    // Compute the roots of the characteristic equation
    double discriminant = b * b - 4 * a * c;
    if (discriminant < 0) { // Complex roots
        lambda1 = -b / (double)(2 * a);
        lambda2 = sqrt(-discriminant) / (2 * a);
    } else if (discriminant == 0) { // Repeated real roots
        lambda1 = lambda2 = -b / (double)(2 * a);
    } else { // Distinct real roots
        lambda1 = (-b + sqrt(discriminant)) / (2 * a);
        lambda2 = (-b - sqrt(discriminant)) / (2 * a);
    }

    // Compute coefficients and display output based on type of roots
    compute_coefficients(lambda1, lambda2, &C1, &C2, &C_alpha, &theta);
    display_output(lambda1, lambda2, C1, C2, C_alpha, theta);

    return 0;
}

void compute_coefficients(double lambda1, double lambda2, double *C1, double *C2, double *C_alpha, double *theta)
{
    if (lambda1 == lambda2) { // Repeated real roots
        *C1 = 1;
        *C2 = 0;
        *C_alpha = lambda1;
        *theta = 0;
    } else if (fabs(lambda1 - lambda2) < 1e-10) { // Distinct real roots (with rounding tolerance)
        *C1 = 1;
        *C2 = lambda1;
        *C_alpha = 0;
        *theta = 0;
    } else { // Complex conjugate roots
        *C1 = 1;
        *C2 = 0;
        *C_alpha = sqrt(lambda1 * lambda1 + lambda2 * lambda2);
        *theta = atan2(lambda2, lambda1);
    }
}

void display_output(double lambda1, double lambda2, double C1, double C2, double C_alpha, double theta)
{
    printf("The roots are:\n");
    printf("lambda1 = %lf\n", lambda1);
    printf("lambda2 = %lf\n", lambda2);

    if (lambda1 == lambda2) { // Repeated real roots
        printf("The solution is: y(t) = (C1 + C2 * t) * e^(%lf t)\n", lambda1);
        printf("Please enter initial conditions y(0) and y'(0):\n");
        double y0, y_prime0;
        scanf("%lf %lf", &y0, &y_prime0);
        C1= y0;
        C2 = y_prime0 - lambda1 * y0;
        printf("The solution is: y(t) = ( %lf + %lf * t ) * e^(%lf t)\n", C1, C2, lambda1);
    } else if (fabs(lambda1 - lambda2) < 1e-10) { // Distinct real roots (with rounding tolerance)
        printf("The solution is: y(t) = (C1 + C2 * t) * e^(%lf t)\n", lambda1);
        printf("Please enter initial conditions y(0) and y'(0):\n");
        double y0, y_prime0;
        scanf("%lf %lf", &y0, &y_prime0);
        C1 = y0;
        C2 = y_prime0 - lambda1 * y0;
        printf("The solution is: y(t) = ( %lf + %lf * t ) * e^(%lf t)\n", C1, C2, lambda1);
    } else { // Complex conjugate roots
        printf("The solution is: y(t) = e^(%lf t) * (C1 * cos(%lf t) + C2 * sin(%lf t))\n", C_alpha, theta, theta);
        printf("Please enter initial conditions y(0) and y'(0):\n");
        double y0, y_prime0;
        scanf("%lf %lf", &y0, &y_prime0);
        C1 = y0;
        C2 = (y_prime0 - lambda1 * y0) / lambda2;
        printf("The solution is: y(t) = e^(%lf t) * ( %lf * cos(%lf t) + %lf * sin(%lf t))\n", C_alpha, C1, theta, C2, theta);
    }
}

Thank you for your help again! Attached is a copy of the question in the assignment as it may clarify things.

Objective: Create a C script that will find the Zero-Input Response of a Second order Linear
Time Invariant System D²y+a₁Dy+a₂ = 0 based on coefficients (a₁ and a₂ ) and initial conditions
(y(0) and y'(0)). (D=d/dt) (Check pages 4 – 8)
Requirements:
Part 1 (Script 1)
1) The user should be prompted to type in coefficients of the Linear Systems and Two Initial
Conditions.
D²y+a₁Dy+a₂ = 0.
2) Find the roots of the second order nontrivial solution.
D²y+a₁Dy+a₂ = 0 => λ²+a₁ λ +a₂ = 0
Create a header file for this step.
Transcribed Image Text:Objective: Create a C script that will find the Zero-Input Response of a Second order Linear Time Invariant System D²y+a₁Dy+a₂ = 0 based on coefficients (a₁ and a₂ ) and initial conditions (y(0) and y'(0)). (D=d/dt) (Check pages 4 – 8) Requirements: Part 1 (Script 1) 1) The user should be prompted to type in coefficients of the Linear Systems and Two Initial Conditions. D²y+a₁Dy+a₂ = 0. 2) Find the roots of the second order nontrivial solution. D²y+a₁Dy+a₂ = 0 => λ²+a₁ λ +a₂ = 0 Create a header file for this step.
Solution
Bartleby Expert
SEE SOLUTION
Follow-up Question

C PROGRAMMING ONLY, Having trouble with this step as well, thank you so much for the help!

NO IOSTREAM.H OR CACIO.H PLEASE I CANT USE THOSE HEADERS.

Modify the given Script to meet the following conditions:


Create a C script that will:


1) Read a text file “Data.txt”. The numbers in the first column of Data.txt are a1’s, the
second column are a2’s, the third column are y(0)s and the fourth column are y’(0)s.


2) Use these numbers to find the Zero-Input Responses. (So, the user will not type in
those numbers. Your program should read those values from the Data.txt file automatically.
Then, your program should compute the roots and required coefficients.)

3) Save the result (Coefficients) on “Result.txt”

Here is the format for Result.txt;
1) The first column indicates whether the system has nonrepeating real roots, repeating
real roots, or complex conjugate roots. Use 1 for nonrepeating real roots, 2 for repeating
real roots, and 3 for complex conjugate roots.
2) The second column should be used for C1 or C’s (for repeating real roots or complex
conjugate)
3) The third column should be used for C2 or C (if it is repeating case) or Theta value
(for complex conjugate case)

Data.txt pasted:

3 2 0 -5
6 9 3 -7
4 40 2 16.78
- 4 4 3 4
5 6 2 -1
4 13 5 15.98
 
Attached is a screenshot of the assignment to help clarify any verbage.
I'm pretty sure you can see the original question this is following up, but I'm gonna paste the script here that needs to be modified, thank you again for your help!:

#include <stdio.h>
#include <math.h>

void compute_coefficients(double lambda1, double lambda2, double *C1, double *C2, double *C_alpha, double *theta);
void display_output(double lambda1, double lambda2, double C1, double C2, double C_alpha, double theta);

int main()
{
    int a, b, c;
    double lambda1, lambda2, C1, C2, C_alpha, theta;

    printf("Enter a, b, and c where a*D2y + b*Dy + c*y = 0:\n");
    scanf("%d%d%d", &a, &b, &c);

    // Compute the roots of the characteristic equation
    double discriminant = b * b - 4 * a * c;
    if (discriminant < 0) { // Complex roots
        lambda1 = -b / (double)(2 * a);
        lambda2 = sqrt(-discriminant) / (2 * a);
    } else if (discriminant == 0) { // Repeated real roots
        lambda1 = lambda2 = -b / (double)(2 * a);
    } else { // Distinct real roots
        lambda1 = (-b + sqrt(discriminant)) / (2 * a);
        lambda2 = (-b - sqrt(discriminant)) / (2 * a);
    }

    // Compute coefficients and display output based on type of roots
    compute_coefficients(lambda1, lambda2, &C1, &C2, &C_alpha, &theta);
    display_output(lambda1, lambda2, C1, C2, C_alpha, theta);

    return 0;
}

void compute_coefficients(double lambda1, double lambda2, double *C1, double *C2, double *C_alpha, double *theta)
{
    if (lambda1 == lambda2) { // Repeated real roots
        *C1 = 1;
        *C2 = 0;
        *C_alpha = lambda1;
        *theta = 0;
    } else if (fabs(lambda1 - lambda2) < 1e-10) { // Distinct real roots (with rounding tolerance)
        *C1 = 1;
        *C2 = lambda1;
        *C_alpha = 0;
        *theta = 0;
    } else { // Complex conjugate roots
        *C1 = 1;
        *C2 = 0;
        *C_alpha = sqrt(lambda1 * lambda1 + lambda2 * lambda2);
        *theta = atan2(lambda2, lambda1);
    }
}

void display_output(double lambda1, double lambda2, double C1, double C2, double C_alpha, double theta)
{
    printf("The roots are:\n");
    printf("lambda1 = %lf\n", lambda1);
    printf("lambda2 = %lf\n", lambda2);

    if (lambda1 == lambda2) { // Repeated real roots
        printf("The solution is: y(t) = (C1 + C2 * t) * e^(%lf t)\n", lambda1);
        printf("Please enter initial conditions y(0) and y'(0):\n");
        double y0, y_prime0;
        scanf("%lf %lf", &y0, &y_prime0);
        C1= y0;
        C2 = y_prime0 - lambda1 * y0;
        printf("The solution is: y(t) = ( %lf + %lf * t ) * e^(%lf t)\n", C1, C2, lambda1);
    } else if (fabs(lambda1 - lambda2) < 1e-10) { // Distinct real roots (with rounding tolerance)
        printf("The solution is: y(t) = (C1 + C2 * t) * e^(%lf t)\n", lambda1);
        printf("Please enter initial conditions y(0) and y'(0):\n");
        double y0, y_prime0;
        scanf("%lf %lf", &y0, &y_prime0);
        C1 = y0;
        C2 = y_prime0 - lambda1 * y0;
        printf("The solution is: y(t) = ( %lf + %lf * t ) * e^(%lf t)\n", C1, C2, lambda1);
    } else { // Complex conjugate roots
        printf("The solution is: y(t) = e^(%lf t) * (C1 * cos(%lf t) + C2 * sin(%lf t))\n", C_alpha, theta, theta);
        printf("Please enter initial conditions y(0) and y'(0):\n");
        double y0, y_prime0;
        scanf("%lf %lf", &y0, &y_prime0);
        C1 = y0;
        C2 = (y_prime0 - lambda1 * y0) / lambda2;
        printf("The solution is: y(t) = e^(%lf t) * ( %lf * cos(%lf t) + %lf * sin(%lf t))\n", C_alpha, C1, theta, C2, theta);
    }
}

 

I'm gonna attach a screenshot of the assignment to clarify any smudgy details. Thanks again!

Part 2 (Script2)
Modify your Script 1 to meet the following conditions.
Create a C script that will
1) Read a text file "Data.txt". The numbers in the first column of Data.txt are aj's, the
second column are a's, the third column are y(0)s and the fourth column are y'(0)s.
2) Use these numbers to find the Zero-Input Responses. (So, the user will not type in
those numbers. Your program should read those values from the Data.txt file automatically.
Then, your program should compute the roots and required coefficients.)
3) Save the result (Coefficients) on "Result.txt"
Here is the format for Result.txt
1) The first column indicates whether the system has nonrepeating real roots, repeating
real roots, or complex conjugate roots. Use 1 for nonrepeating real roots, 2 for repeating
real roots, and 3 for complex conjugate roots.
2) The second column should be used for C1 or C's (for repeating real roots or complex
conjugate)
3) The third column should be used for C2 or C (if it is repeating case) or Theta value
(for complex conjugate case)
Transcribed Image Text:Part 2 (Script2) Modify your Script 1 to meet the following conditions. Create a C script that will 1) Read a text file "Data.txt". The numbers in the first column of Data.txt are aj's, the second column are a's, the third column are y(0)s and the fourth column are y'(0)s. 2) Use these numbers to find the Zero-Input Responses. (So, the user will not type in those numbers. Your program should read those values from the Data.txt file automatically. Then, your program should compute the roots and required coefficients.) 3) Save the result (Coefficients) on "Result.txt" Here is the format for Result.txt 1) The first column indicates whether the system has nonrepeating real roots, repeating real roots, or complex conjugate roots. Use 1 for nonrepeating real roots, 2 for repeating real roots, and 3 for complex conjugate roots. 2) The second column should be used for C1 or C's (for repeating real roots or complex conjugate) 3) The third column should be used for C2 or C (if it is repeating case) or Theta value (for complex conjugate case)
Solution
Bartleby Expert
SEE SOLUTION
Knowledge Booster
Intelligent Machines
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education