# Matlab Extrapolation: Find Approximate Size of Matrix n∗

• JesseJC
In summary, the conversation involves determining the approximate size of matrix n at which the mean error for Gaussian Elimination is equal to the vector x. This is done by running the calculation multiple times with different realizations of A and extrapolating the data. The code provided plots log10(En) versus log10(n) and performs a third degree polynomial fit to estimate the value of n∗. The conversation also suggests repeating the process with a random upper-triangular matrix, but extrapolation is not necessary here. The final report should include a plot of log10(En) versus n, justification for the chosen values of n and M, explanation of the extrapolation method, and an estimation of n∗.

#### JesseJC

Moved from a technical forum, so homework template missing
1. Let A be a random n×n matrix, x = (1,1,...,1)⊤ be an n-vector of ones and b = Ax be the right-hand side vector. As in class, let z = (zj) ∈ Rn be the result of solving the system Ax = b in finite precision using the backslash command. To measure the error between x and z, we let

δ= max |xj−zj|, j =1,...,n

be the maximum componentwise difference between the two vectors. Since A is a random matrix, we need to run this calculation a number of times with different realizations of A in order to get a reasonable value for δ. Let M be the number of trials and suppose that for the kth trial the error is δ(k). We define the mean error as follows:

En = 1/M[δ^(1) +δ^(2) +...+δ^(M)]

Your goal is to determine the approximate size of matrix n = n∗ at which the mean error for Gaussian Elimination is En ≈ 1. In other words, the point at which round-off error in Gaussian elimination is of the same magnitude as the vector x.

In practice, your computer will not have the memory or processing power to find n∗ exactly. Instead, you should extrapolate your data. Find En for reasonable values of n, make a plot of log10(En) versus log10(n) and then perform a suitable extrapolation.

Your conclusions should be explained in a one-page report. Your report should include the following:

(a) A plot of log10(En) versus log10(n).
(b) Justification for the values of n and M you chose.
(c) Explanation of how you do the extrapolation.
(d) An estimation of the number n∗.

Finally, replace A be an random upper-triangular matrix and repeat the process. Hint: you should not need to do the extrapolation step here. You may also wish to plot log10(En) against n here, rather than log10(n).

Code so far:
n = 20:20:500;

M = 200;

mean_error = zeros(length(n),1);

for j = 1:length(n)

error = zeros(M,1);

x = ones(n(j),1);

for i = 1:M

A = randn(n(j),n(j));

b = A*x;

z = A\b;

error(i) = max(abs(z-x));

end

mean_error(j) = mean(error);

mean_error(j)

end

plot(log10(mean_error), log10(n))

Hi everyone, I've attached a .pdf file to show you where I've gotten so far. I'm having a hard time extrapolating the line though, could anyone give me some tips? One of my classes teaching assistants said that polynomial fitting would work well here, but I've tried that and I could not figure it out.

#### Attachments

• extrapolation.pdf
2.2 KB · Views: 299
I've found the curve fitting tool, and I've managed to fit it into a third degree polynomial, but I cannot seem to save the file/call the function correctly to open it in my code...Fantastic. There must be an easier way to do this.

I think it looks like a power function. It is nearly linear on log-log.

JesseJC
mfig said:
I think it looks like a power function. It is nearly linear on log-log.

I got it, looks similar to mine. Thanks.

## 1. What is Matlab extrapolation and how is it used to find the approximate size of a matrix?

Matlab extrapolation is a method used to estimate the value of a function outside the range of known data points. In the context of finding the approximate size of a matrix, it involves using the known values of the matrix to predict the size of the matrix. This is useful in cases where the size of the matrix is not explicitly stated or when dealing with large data sets.

## 2. How accurate is the approximate size obtained through Matlab extrapolation?

The accuracy of the approximate size obtained through Matlab extrapolation depends on the quality and quantity of the known data points. Generally, the more data points available, the more accurate the extrapolated size will be. However, it is important to note that this method is still an estimation and may not always be perfectly accurate.

## 3. Can Matlab extrapolation be used to find the size of any type of matrix?

Yes, Matlab extrapolation can be used to find the size of any type of matrix, as long as there are enough known data points to make a reasonable estimate. This method is commonly used in various fields such as mathematics, physics, and engineering.

## 4. Are there any limitations to using Matlab extrapolation for finding the approximate size of a matrix?

One limitation of using Matlab extrapolation is that it relies on the assumption that the data follows a certain pattern or trend. If the data does not follow a clear pattern, the extrapolated size may not be accurate. Additionally, this method may not work well with highly complex or nonlinear data sets.

## 5. Are there any alternative methods for finding the approximate size of a matrix?

Yes, there are alternative methods for finding the approximate size of a matrix, such as using matrix algebra or built-in functions in Matlab. However, Matlab extrapolation can be a useful tool when dealing with large data sets or when the size of the matrix is not explicitly stated.