You are Here: Home

Announcements Posted on
Would YOU be put off a uni with a high crime rate? First 50 to have their say get a £5 Amazon voucher! 27-10-2016
1. I'm trying to do the polynomial curve-fitting part of this pdf (attached). I'm having trouble calculating the coefficients. I get no 0th order coefficient. I'm also having a lot of trouble with the ' \ ' operator because even when the length of v and A match up (or should do) it says the matrix size is wrong.

This is my code
Code:
```function[] = C002v2_2()
start = 0;
fin = 200;
n = 100;
div = (fin - start)/n;
c1 = [1.5, -2.5, 0.7, -1.2];
e = 0.01;
x = startfin;
y = x;
for i = 1:n
y(i) = c1(1) + c1(2) * x(i) + c1(3) * x(i)^2 + c1(4) * x(i)^3 + e * randn();
end
v = zeros(4,1);
for k = 1:4
for i = 1:n
v(k) = v(k) + y(i)*x(i)^k;
end
end
A = zeros(4, 3);
for k = 1:4
for i = 1:3
for j = 1:n
A(k,i) = A(k,i) + x(j)^(i+k);
end
end
end
%A
%v
c2 = A \ v;
%c2
yf = c2(1) + c2(2) * x + c2(3) * x.^2 + c2(4) * x.^3;
f = figure();
plot(x, y, x, yf);
end```
Thanks so much. I'm desperate.
Attached Images
2. C002.pdf (188.2 KB, 33 views)

## Register

Thanks for posting! You just need to create an account in order to submit the post
1. this can't be left blank
2. this can't be left blank
3. this can't be left blank

6 characters or longer with both numbers and letters is safer

4. this can't be left empty
1. Oops, you need to agree to our Ts&Cs to register

Updated: March 29, 2016
TSR Support Team

We have a brilliant team of more than 60 Support Team members looking after discussions on The Student Room, helping to make it a fun, safe and useful place to hang out.

This forum is supported by:
Today on TSR

### University open days

Is it worth going? Find out here

Poll
Useful resources