# Discussion Board for 02601
At here, you can post your questions, and can also answer the questions posted by the others.
- You can write mathematical expressions as in Latex, e.g. $\lambda=1$.
- You can insert your code in your question in Matlab (or other programming language) format. You can do like this:
``` matlab=
function f = myfun(x)
if x > 1
x = x + 1;
end
```
- You also can include images, tables, etc..
*Now let's try it out.* :smile:
## Q & A:
1. Question 1: I dont get a good approx-curve, what is wrong(2.1)?
plot(x,y,'.');
A = [x sin(x) cos(x) sin(2*x) cos(2*x)];
c = (A'*A\A'*y);
xx = linspace(0,10);
yy = c(1)*xx+c(2)*sin(xx) + c(3)*cos(xx)+c(4)*sin(2*xx)+c(5)*cos(2*xx);
plot(x,y,'k.',xx,yy,'-g')
Answer: I can see two mistakes:
- The backslach was wrong. It should be (A'*A)/(A'*y);
- The second mistake is the system matrix $A$. You miss the basis function $1$, i.e., it should be A=[ones(size(x)), x, sin(x), cos(x), sin(2x), cos(2x)];
----
2.Question 2: Not getting correct horner in matlab's ready function (for question 1.2)
syms x
q=5*(exp(x))^3+7*(exp(x))^2+9*exp(x)+11;
horner(q)
I get this as an answer:
7*exp(2*x) + 5*exp(3*x) + 9*exp(x) + 11
Instead of
11+exp(x)*(9+exp(x)*(7+exp(x)*(5)))
Why is that?
Answer: I don't understand your question. In this question also all exercises questions, we do not need symbolic calculation. Matlab is not designed for that.
---
3. Question about the eps = 2u in exercise 3.3
What does it mean that the error, epsilon, has to equal 2u? I found in the slides, that the
'eps = 2u' is called a 'machine epsilon' but in the context of exercise 3.3, I dont understand what it means.
Answer: Here I just want to show how you can get this 2u, basically call matlab function eps.
---
4. Question for Homework 1:
In Q5.2.3 do we use matlab for the 4 iterations or by hand?
Answer: In matlab.
---
5. Question for Homework 1:
Are we allowed to reuse code from exercise solutions in the Homework?
Answer: Yes, of course.
---
6. Question on cardinal polynomiums in exercise 7.1
I made my CardinalPolynomial.m function so that it gives L0, L1, L2 etc as output and obtained this figure, but from the solution it seems like you should only get one cardinal polynomium out? or what?

``` matlab=
function Li = CardinalPolynomial(nodes, i, t)
Li = ones(length(nodes),length(t));
for ii = 1:i
for j = 1:length(nodes)
if j~= ii
Li(ii,:)=Li(ii,:).*(t - nodes(j))./(nodes(ii)-nodes(j));
end
end
end
end
```
Maybe I have understood it in a wrong way?
Answer: According to the inputs and the outputs given in Exercise 7.1, it should be only one cardinal polynomial, $l_i$. The output is a vector, which gives the values of $l_i$ at all $t_i$.
---
7. Question for 7.4 and 7.5:
Just to check if I understood the exercises properly, - we are supposed to get the ydata by evaluating f(x) at the nodes, correct? Cause I don't see any other way of getting the ydata, but this is of course also assuming we're supposed to find the interpolating polynomial, or did I misunderstand something?
Answer: That's correct. Since you apply interpolation to approximate $f(x)$, the table should be with $x_i$ and $f(x_i)$.
---
8. M in 7.4.1
How do I determine the M in exercise 7.4.1 for the upper bound?
Or, should i use lemma 1 without the M?
Answer: Since you know the function $f(x)$, then you can calculate its $(n+1)$th derivative. Then, according to the interval, you can find the upper bound. Please see the example in the slides page 28.
---
9. Calculate p12 and pn in 7.4 and 7.5
How to calculate p12 in exercise 7.4? And pn in 7.5? Do I use polyfit/polyval in MATLAB or what is the approach?
Answer: After exercise 7.1 and 7.2, you have implemented the Lagrange form. You should use your implementation here.
---
10. exercise 8.1 (5.3.3 in book)
For composite trapezoid rule: How to calculate Et??? (the f''(ei) part)
Answer: Here we do not consider the error esitmation.
---
How to make the function odefun?
_______
17-D
how do we know which intergration (Trapezoid or Simpson's) should we use in question D?
Answer: Hi, in the book on page 313
------
Hi!
Is it correctly understood that if our 3 first assignments are passed then we do not need to hand in the last one? :)