// Example program #include using namespace std; void EulerF(float x0, float y0,
ID: 3744040 • Letter: #
Question
// Example program
#include
using namespace std;
void EulerF(float x0, float y0, float h, float x) { //Euler method for f(x)
while (x0 < x) {
float temp = y0;
y0 = (2 * y0) + (y0 * h) ; //df/dx = 2f
x0 = x0 + h;
cout << "Solution at x = " << x0 << " is " << y0 << endl;
}
}
void EulerR(float t0, float s0, float k, float t) { //Euler method for r(t)
while (x0 < x) {
float temp = s0;
s0 = (10 * s0) - 2 * Euler(x0, y0, h, x) ; //dr/dt = 10r - 2f
t0 = t0 + k;
cout << "Solution at x = " << t0 << " is " << s0 << endl;
}
}
int main() {
float x0 = 0;//initial x value
float t0 = 0;
float y0 = 5; //initial y value
float s0 = 100;
float h,k = 1; // mesh size
float x;
float s;
cin >> x;
cin >> s;
EulerF(x0, y0, h, x);
EulerR(t0, s0, k, t);
return 0;
}
(0) 100. f(0) = 5Explanation / Answer
// Hey here is solution.
// I have cleared all errors, those were there. Code is refined for clear understanding. Hope it helps
// Note : I knows little about Euler Method. If output is not as expected. Please provide more details about eular formula specific to question functions. So that i can modify the computer program accordingly & update here.
// Please upvote if you find it useful. Thanks
// Example program
#include<iostream>
using namespace std;
float EulerF(float x0, float y0, float step, float x) { //Euler method for f(x)
while (x0 <= x) {
float temp = y0;
y0 = (2 * y0) + (y0 * step); //df/dx = 2f
x0 = x0 + step;
}
cout << " Value of y at x = " << x << " is " << y0 << endl;
return y0;
}
void EulerR(float s0, float t0, float step, float s) { //Euler method for r(t)
while (s0 <= s) {
float temp = t0;
t0 = (10 * t0) - (2 * EulerF(s0, t0, step, s)); //dr/dt = 10r - 2f
s0 = s0 + step;
cout << " Value of t at s = " << s << " is " << t0 << endl;
}
}
int main() {
float x0 = 0;//initial x value
float s0 = 0;
float y0 = 5; //initial y value
float t0 = 100;
float step = 1; // mesh size
float x;
float s;
cout << "Its assumed that Function F takes value x and gives out value y Simillarly Function R takes value s and gives out value t ";
cout << "Function F : Enter input value X= ";
cin >> x;
EulerF(x0, y0, step, x);
cout << " Function R : Enter input value S= ";
cin >> s;
EulerR(s0, t0, step, s);
int temp;
cin >> temp;
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.