TAILIEUCHUNG - Computational Physics - M. Jensen Episode 1 Part 4

Tham khảo tài liệu 'computational physics - m. jensen episode 1 part 4', kỹ thuật - công nghệ, cơ khí - chế tạo máy phục vụ nhu cầu học tập, nghiên cứu và làm việc hiệu quả | . NUMERICAL DIFFERENTIATION 49 computed_derivative new double number_of_steps compute the second derivative of exp x second_derivative number_of_steps x initial_step h_step computed_derivative Then we print the results to file output h_step computed_derivative x number_of_steps fr e e memory delete h_step delete computed_derivative return 0 end main program We have defined three additional functions one which reads in from screen the value of the initial step length and the number of divisions by 2 of h. This function is called initialise . To calculate the second derivatives we define the function second_derivative . Finally we have a function which writes our results together with a comparison with the exact value to a given file. The results are stored in two arrays one which contains the given step length and another one which contains the computed derivative. These arrays are defined as pointers through the statement double h_step computed_derivative A call in the main function to the function second_derivative looks then like this second_derivative number_of_steps x h_step computed_derivative while the called function is declared in the following way void second_derivative int number_of_steps double x double h_step double computed_deriva indicating that double h_step double computed_derivative are pointers and that we transfer the address of the first elements. The other variables int number_of_steps double x are transferred by value and are not changed in the called function. Another aspect to observe is the possibility of dynamical allocation of memory through the new function. In the included program we reserve space in memory for these three arrays in the following way h_step new double number_of_steps and computed_derivative new double number_of_steps When we no longer need the space occupied by these arrays we free memory through the declarations delete h_step and delete computed_derivative The function initialise Read in from screen the initial and

TỪ KHÓA LIÊN QUAN
TAILIEUCHUNG - Chia sẻ tài liệu không giới hạn
Địa chỉ : 444 Hoang Hoa Tham, Hanoi, Viet Nam
Website : tailieuchung.com
Email : tailieuchung20@gmail.com
Tailieuchung.com là thư viện tài liệu trực tuyến, nơi chia sẽ trao đổi hàng triệu tài liệu như luận văn đồ án, sách, giáo trình, đề thi.
Chúng tôi không chịu trách nhiệm liên quan đến các vấn đề bản quyền nội dung tài liệu được thành viên tự nguyện đăng tải lên, nếu phát hiện thấy tài liệu xấu hoặc tài liệu có bản quyền xin hãy email cho chúng tôi.
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.