You are required to develop a computer code that that can solve systems of ODE. The...

Free

70.2K

Verified Solution

Question

Mechanical Engineering

You are required to develop a computer code that that can solvesystems of ODE. The code should request the user to choose one ofthe following methods for solving the system:

? Euler

? 4th Order Runge Kutta  

Answer & Explanation Solved by verified expert
4.2 Ratings (834 Votes)

For ODE ...

1). EULAR'S METHOD C-CODE :

\"

#include

float fun(float x,float y)

{

    float f;

    f=x+y;

    return f;

}

main()

{

    float a,b,x,y,h,t,k;

    printf(\"\nEnter x0,y0,h,xn: \");

    scanf(\"%f%f%f%f\",&a,&b,&h,&t);

    x=a;

    y=b;

    printf(\"\n  x\t  y\n\");

    while(x<=t)

    {

        k=h*fun(x,y);

        y=y+k;

        x=x+h;

        printf(\"%0.3f\t%0.3f\n\",x,y);

    }

} \"

2). 4TH ORDER RUNGE KUTTA METHOD C-CODE :

\"
#include
#include
float f(float x,float y);
int main()
{
    float x0,y0,m1,m2,m3,m4,m,y,x,h,xn;
    printf(\"Enter x0,y0,xn,h:\");
    scanf(\"%f %f %f %f\",&x0,&y0,&xn,&h);
    x=x0;
    y=y0;
    printf(\"\n\nX\t\tY\n\");
    while(x     {
        m1=f(x0,y0);
        m2=f((x0+h/2.0),(y0+m1*h/2.0));
        m3=f((x0+h/2.0),(y0+m2*h/2.0));
        m4=f((x0+h),(y0+m3*h));
        m=((m1+2*m2+2*m3+m4)/6);
        y=y+m*h;
        x=x+h;
        printf(\"%f\t%f\n\",x,y);
    }
}
float f(float x,float y)
{
    float m;
    m=(x-y)/(x+y);
    return m;
} \"


Get Answers to Unlimited Questions

Join us to gain access to millions of questions and expert answers. Enjoy exclusive benefits tailored just for you!

Membership Benefits:
  • Unlimited Question Access with detailed Answers
  • Zin AI - 3 Million Words
  • 10 Dall-E 3 Images
  • 20 Plot Generations
  • Conversation with Dialogue Memory
  • No Ads, Ever!
  • Access to Our Best AI Platform: Flex AI - Your personal assistant for all your inquiries!
Become a Member

Other questions asked by students