Похожие чаты

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 ответов

14 просмотров

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; } 🙃

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

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

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
Anyone knows where there are some instructions or discort about failed bridge transactions ?
Jochem
21
есть ПО, которое лежит папкой, по сути и не инсталится, а просто запускается. Надо раскидать по машинам в домене. Я так понял, что прям настройками GPO, копировать я смогу тол...
Dmitriy
8
any reference of this implementation?
BitBuddha
29
Чёт не понял, я ж правильной функцией воспользовался чтобы вывести отладочную информацию? но что-то она не ловится
notme
18
Привет)) уже кажется эту тему перемусолили, но вот я так и не понял. Я сейчас сижу на 27дюймов 2к мониторе. На Актуальной макоси, если я куплю 27д 4к монитор: - будет ли изобр...
Vladislav Piskunov
16
Добрый день! Скажите пожалуйста, а какие программы вы бы рекомендовали написать для того, чтобы научиться управлять памятью? Можно написать динамический массив, можно связный ...
Филипп
7
Also, why can’t the community have a vote/ say when it comes to initiatives like buybacks. Isn’t the point of crypto decentralisation? Don’t we deserve input as long term supp...
👨🏽‍🦰
13
Карта сайта