Похожие чаты

Https://Pastebin.Com/GsiNuxSK Hi every body, in this code x0 should change from

0 to 1 but it doesn't. could anybody help me to solve this problem?

24 ответов

18 просмотров

Could it be because you change its value after writing to the file?

Paria.-Z Автор вопроса

Is this how you write output?? #include <iostream> #include <fstream> using namespace std; int main() { ofstream myfile("RK-exam.txt"); int n; double a=0, b=1, h=0.1; n = (b - a) / h; double x=a,XX, y=1,YY, k,KK; double prime; for (int i = 0; i < n; i++) { prime = ((-1)*x*y) + ((4*x)/y); KK = h * prime; x = x + (h/3); YY = y + (KK/3); prime = ((-1)*x*YY) + ((4*x)/YY); k = h * prime; XX = x + ((2*h)/3); y = YY + ((2*k)/3); prime = ((-1)*XX*y) + ((4*XX)/y); k = h * prime; x = XX; y = YY + (1/4) * (KK + (3*k)); cout << x << "\t" << y << endl; myfile << x << "\t" << y << endl; } myfile.close(); return 0; } 🙃

Aakash Saini
Is this how you write output?? #include <iostrea...

See the magic!! Change value of h=0.1 to 0.01🙃

Paria.-Z Автор вопроса
Aakash Saini
Is this how you write output?? #include <iostrea...

yes,,it's solved, thx,🌷 but the point is that h should be 0.1😅

Paria.-Z Автор вопроса
Paria. Z
yes,,it's solved, thx,🌷 but the point is that h sh...

I mean the const numbers should not be changed, I think there is s.th wrong in the for loop🤔

Paria.-Z Автор вопроса
Aakash Saini
Now probs! Let people play with “h”😜

excuse me, I think you didn't change the value of h🤔, in here we don't have x1, x2,x3. would you explain why you didn't use it?

Paria.-Z Автор вопроса
Aakash Saini
In short!! I squeezed your logic😄

I know😅, actually this why I have struggle with programming, take a look at this code, if you don't mind #include <iostream> #include <fstream> #include <cmath> using namespace std; int main() { ofstream myfile("RK4.txt"); double k1, k2, k3, k4, x0, x1, x2, x3, x4, y0,y1, y2, y3, y4, y_1_prime, y_2_prime, y_3_prime, y_4_prime, a, b, h, y_new; int n; const double e = 2.71828; a = 0; b = 1; h = 0.1; n = (b - a) / h; x0 = a; y0 = 1; cout<<"y0"<<y0<<endl; for (int i = 0; i <= n; i++) { x1 = x0; cout<<"x1="<<x1<<endl; y1= y0; y_1_prime = ((5 * pow(x1, 2)) - y1) / pow(e, (x1 + y1)); k1 = h * y_1_prime; x2 = x1 + (h / 2);cout<<"x2="<<x2<<endl; y2 = y1 + (k1 / 2); y_2_prime = ((5 * pow(x2, 2)) - y2) / pow(e, (x2 + y2)); k2 = h * y_2_prime; x3 = x1 + (h / 2);cout<<"x3="<<x3<<endl; y3 = y1 + (k2 / 2); y_3_prime = ((5 * pow(x3, 2)) - y3) / pow(e, (x3 + y3)); k3 = h * y_3_prime; x4 = x1 + h;cout<<"x2="<<x4<<endl; y4 = y1 + k3; y_4_prime = ((5 * pow(x4, 2)) - y4) / pow(e, (x4 + y4)); k4 = h * y_4_prime; y_new = y1 + (k1 + 2 * k2 + 2 * k3 + k4) / 6; cout << x0 << "\t" << y_new << endl; //cout<<"k1="<<k1<<" k2="<<k2<<" k3="<<k3<<" k4="<<k4<<endl; myfile << x0 << "\t" << y_new << endl; y0 = y_new; x0 = x4; } myfile.close(); return 0; }

Paria.-Z Автор вопроса
Paria. Z
I know😅, actually this why I have struggle with p...

in here I used x1, x2,x3,...and it works accurately

Paria. Z
excuse me, I think you didn't change the value of ...

Just modify little and counter will move from 0 to 1, as of now it’s moving it from 0.1 to 1; Here.. — ... for (int i=0; i<n; i++) { cout << x << "\t" << y << endl; myfile << x << "\t" << y << endl; prime = ((-1)*x*y) + ((4*x)/y); KK = h * prime; x = x + (h/3); YY = y + (KK/3); prime = ((-1)*x*YY) + ((4*x)/YY); k = h * prime; XX = x + ((2*h)/3); y = YY + ((2*k)/3); prime = ((-1)*XX*y) + ((4*XX)/y); k = h * prime; x = XX; y = YY + (1/4) * (KK + (3*k)); } cout << x << "\t" << y << endl; myfile << x << "\t" << y << endl; ...

Paria.-Z Автор вопроса
Paria. Z
in here I used x1, x2,x3,...and it works accuratel...

but in the previous code it didn't and just God knows why I think😁

Paria. Z
in here I used x1, x2,x3,...and it works accuratel...

It’s still the same!! Just the same variables are getting overwritten.

Paria.-Z Автор вопроса
Paria. Z
I didn't understand🤔

Instead of using x1,2,3 y1,2,3 prime1,2,3 .. I just deduced the code logic to limited use. That make code more reasonable at assembly level and gets optimized well; else you are creating unnecessary variables which are not good for optimization. Smart codes gets optimized at assemble smartly by compiler for better executing! This is just a small code! Habits make big code smartly driven and well optimized. 🤪😄

Paria.-Z Автор вопроса
Aakash Saini
Instead of using x1,2,3 y1,2,3 prime1,2,3 .. I jus...

you're right👌👌, I forgot that factor😅 would you give me some tips improve this skill except practicing? Do you know any special course?😁 how can I learn coding smartly?

Paria. Z
you're right👌👌, I forgot that factor😅 would you gi...

Code regularly!! It’s more like a fitness program😄

Paria.-Z Автор вопроса
Aakash Saini
Code regularly!! It’s more like a fitness program😄

😂👌, it's the same as practicing😁, thx for your time🙏

Paria. Z
I know😅, actually this why I have struggle with p...

Learning is the key... Thought to change it with lambda.. — include <iostream> #include <fstream> #include <cmath> using namespace std; int main() { ofstream myfile("prime-test.txt"); int n; double a=0, b=1, h=0.1; n = (b-a)/h; double x=a, _x; double y=1, _y; double k, _k; cout.setf(ios::fixed); cout.precision(7); cout << x << ":—\t" << y << endl; myfile << x << ":—\t" << y << endl; auto primeX = [] (double x, double y) { const double c = 2.71828; double prime = ((5*pow(x,2))-y)/pow(c,(x+y)); double k = (0.1*prime); return (k); }; for(int i=0; i<n; i++) { _x = x; _y = y; k = primeX(_x, _y); //1 _k = (k+2); _x = x + (h/2); _y = y + (k/2); k = primeX(_x, _y); //2 _k = _k*(k+2); _x = x + (h/2); _y = y + (k/2); k = primeX(_x, _y); //3 _k = _k*(k); _x = x + h; _y = y + k; k = primeX(_x, _y); //4 _k = _k+(k); x = _x; y = y + (_k)/6; cout << x << ":—\t" << y << endl; myfile << x << ":—\t" << y << endl; } myfile.close(); return 0; } 🙃

Похожие вопросы

Обсуждают сегодня

Господа, а что сейчас вообще с рынком труда на делфи происходит? Какова ситуация?
Rꙮman Yankꙮvsky
29
А вообще, что может смущать в самой Julia - бы сказал, что нет единого стандартного подхода по многим моментам, поэтому многое выглядит как "хаки" и произвол. Короче говоря, с...
Viktor G.
2
@Benzenoid can you tell me the easiest, and safest way to bu.y HEX now?
Živa Žena
20
This is a question from my wife who make a fortune with memes 😂😂 About the Migration and Tokens: 1. How will the old tokens be migrated to the new $LGCYX network? What is th...
🍿 °anton°
2
30500 за редактор? )
Владимир
47
а через ESC-код ?
Alexey Kulakov
29
What is the Dex situation? Agora team started with the Pnetwork for their dex which helped them both with integration. It’s completed but as you can see from the Pnetwork ann...
Ben
1
Гайс, вопрос для разносторонее развитых: читаю стрим с юарта, нада выделять с него фреймы с определенной структурой, если ли чо готовое, или долбаться с ринг буффером? нада у...
Vitaly
9
Anyone knows where there are some instructions or discort about failed bridge transactions ?
Jochem
21
@lozuk how do I get my phex copies of my ehex from a atomic wallet, to move to my rabby?
Justfrontin 👀
11
Карта сайта