PLEASE HELP ME FIGURE OUT THIS CODE I dont think i did the step size right This
ID: 3702284 • Letter: P
Question
PLEASE HELP ME FIGURE OUT THIS CODE
I dont think i did the step size right
This is my code but its not working PLEASE HELP me figure out whats wrong
#include<stdio.h>
float func(float x,float y);
float euler(float x0,float xn,float y0,int n);
int main(){
float x0,xn,y0,e;
int n;
printf(" inputn: ");
scanf("%d",&n);
printf("input x0: ");
scanf("%f,%f",&x0);
printf("input xn: ");
scanf("%f,%f",&xn);
printf("input y0: ");
scanf("%f",&y0);
e=euler(x0,xn,y0,n);
}
float func(float x,float y){
return (x^2-(3x));
}
float euler(float x0,float xn,float y0,int n){
float x,y,h;
int i;
x=x0;
y=y0;
h=(xn-x0)/n;
printf("y(%f)=%6.4f ",x0,y0);
for(i=1;i<=n;i++) {y=y+h*func(x,y);
x=x0+i*h;
printf("y(%f)=%6.4f ",x,y);}
return y;
}
Develop a C-code to meet the requirements below: 1) Find the solution of the differential equation below by using Euler's method. The range of x is 2 to 3 dy/dx-x'-3x with y-3 at x-2 2) Find the appropriate step size for this specific problem 3) Print all the y values within the range of x 2 to x-3.Explanation / Answer
#include<stdio.h>
float func(float x,float y);
float euler(float x0,float xn,float y0,int n);
int main(){
float x0,xn,y0,e;
int n;
printf(" inputn: ");
scanf("%d",&n);
printf("input x0: ");
scanf("%f",&x0);
printf("input xn: ");
scanf("%f",&xn);
printf("input y0: ");
scanf("%f",&y0);
e=euler(x0,xn,y0,n);
}
float func(float x,float y){
return ((x*x)-(3*x));
}
float euler(float x0,float xn,float y0,int n){
float x,y,h;
int i;
x=x0;
y=y0;
h=(xn-x0)/n;
printf("y(%f)=%6.4f ",x0,y0);
for(i=1;i<=n;i++) {y=y+h*func(x,y);
x=x0+i*h;
printf("y(%f)=%6.4f ",x,y);}
return y;
}
//for further clarification give comments. thank you:)
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.