You are Here: Home

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, 116 views)

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:
Updated: March 29, 2016
Today on TSR

### What is the latest you've left an assignment

And actually passed?

### Simply having a wonderful Christmas time...

Discussions on TSR

• Latest
• ## See more of what you like on The Student Room

You can personalise what you see on TSR. Tell us a little about yourself to get started.

• Poll
Useful resources

Can you help? Study Help unanswered threadsStudy Help rules and posting guidelines

## Groups associated with this forum:

View associated groups
Discussions on TSR

• Latest
• ## See more of what you like on The Student Room

You can personalise what you see on TSR. Tell us a little about yourself to get started.

• The Student Room, Get Revising and Marked by Teachers are trading names of The Student Room Group Ltd.

Register Number: 04666380 (England and Wales), VAT No. 806 8067 22 Registered Office: International House, Queens Road, Brighton, BN1 3XE

Reputation gems: You get these gems as you gain rep from other members for making good contributions and giving helpful advice.