Matlab/c++ programming question

  • Thread starter Rachelross
  • Start date
  • Tags
    Programming
In summary, for this programming question, you will need to use Simpson's rule and explore the effect of changing the strip size on the error, as well as compare the convergence of the integral for different strip sizes in the left-hand and right-hand rules for integration.
  • #1
Rachelross
4
0
Matlab/c++ programming question please help:)

Homework Statement



Look up Simpson’s Rule and explore the effect on this integration method of
changing the strip size on the error. Also, explore the effect of changing the strip size
in the left-hand and right-hand rules for integration. Compare the convergence of the
integral as the strip size decreases for all four integration methods

Homework Equations


Simpson's rule
The integration formula I =∫f (x) dx (The interval is from a to b)
The integration approximation formula I ≈ Δx( (y0 + yn )/2+ Σ yi)



The Attempt at a Solution


Okay I do not want a solution but maybe some hints as I have no idea how to start this program
 
Physics news on Phys.org
  • #2
. For the Simpson's rule, you can use a numerical integration technique that is based on the trapezoid rule. The trapezoid rule is a way of approximating the area under a curve by dividing it up into sections or "strips" and calculating the area of each strip. You can then calculate the total area under the curve by summing up the areas of all the strips. Simpson's rule improves upon the trapezoid rule by using a polynomial function to approximate the area. In Simpson's rule, the area of each strip is calculated using a third-order polynomial instead of the linear function used in the trapezoid rule. In order to explore the effect of changing the strip size on the error, you can calculate the error for each strip size. To do this, you will need to calculate the exact integral value for comparison and then compare this to the value obtained from Simpson's rule. You can then calculate the error for each strip size and plot the results to see how the error changes as the strip size decreases. To explore the effect of changing the strip size in the left-hand and right-hand rules for integration, you can again calculate the exact integral value for comparison and then compare this to the values obtained from the left-hand and right-hand rules. Again, you can calculate the error for each strip size and plot the results to see how the error changes as the strip size decreases. Finally, you can compare the convergence of the integral as the strip size decreases for all four integration methods by plotting the errors for each method and comparing the results.
 

FAQ: Matlab/c++ programming question

What is the difference between Matlab and C++?

Matlab is a high-level programming language commonly used for mathematical and scientific computation, while C++ is a general-purpose programming language. Matlab is easier to learn and use, but C++ offers more control and flexibility for advanced programming tasks.

Can I use both Matlab and C++ in the same project?

Yes, you can use both languages in the same project. Matlab allows for easy integration with C++ through the use of MEX files, which allows for calling C++ functions from within Matlab code.

Which language is better for numerical calculations, Matlab or C++?

Matlab is specifically designed for numerical calculations and has built-in functions for linear algebra, optimization, and other mathematical operations. C++, on the other hand, requires more coding for these types of calculations. Therefore, Matlab is generally considered better for numerical calculations.

Is it possible to convert Matlab code to C++?

Yes, it is possible to convert Matlab code to C++. There are various tools and libraries available that can assist with this conversion. However, the resulting C++ code may not be as efficient as code written directly in C++.

Can I use C++ libraries in Matlab?

Yes, it is possible to use C++ libraries in Matlab through the use of MEX files. This allows for the integration of existing C++ code into Matlab projects, providing access to a wider range of functions and capabilities.

Similar threads

Replies
10
Views
2K
Replies
7
Views
2K
Replies
2
Views
1K
Replies
7
Views
4K
Replies
4
Views
2K
Replies
12
Views
2K
Replies
23
Views
2K
Replies
1
Views
2K
Replies
2
Views
4K
Back
Top