From: dingz on 31 Mar 2010 08:25 Hello, I'm new on this forum. I've got a question regarding matlab, i'm stuck with this little problem for hours and i can't seem to figure out how to fix it. Here's my following code of importance: function y = opdracht3(n) i = 0; h = 0; f = 0; while i <= n z = inline('exp(x).*(x.^i)'); a = quadl(z, -1, 1); f = [f a]; if h == 0 f = [a]; h = h + 1; end i = i + 1; end f My problem lies within this code only, i'm sure. Anyway, if i try to solve this (as in type opdracht3(2) in matlab for example) it gives me the warning mentioned in the topic title. Apparently it's coming close to dividing to zero or something so the integrand becomes too big a number. But that shouldn't be the case since for n = 2, i will be equal to 0 at first loop, 1 at second loop, and 2 at third and last loop. I've tried filling in 0, 1 and 2 instead of i respectively at z = inline('exp(x).*(x.^i)'); Then it works fine. If i then try to compute opdracht3(2) it gives me the correct integral 3 times. (for opdracht3(5) i would get the same integral 6 times) Does anyone have a clue how to solve this?
From: dingz on 31 Mar 2010 09:55 i tried that, but apparently my version of matlab doesnt support it. And its a school assignment, the pc's are pretty old, so im not sure if the school's version has it neither. my matlab version is 6.5 btw. Anyway, thanks for the reply :p any other suggestion?
From: dingz on 31 Mar 2010 12:15 Unfortunately i tried that a million times too, adding 'x' doesnt change anything since it seems to be default and adding any more parameters after that messes up my integral function. Anyway, i gave up on this and i used a while lus to work out the integral. The code is a bit messy and i feel like things couldve been way easier but it works now xD thanks anyway!
|
Pages: 1 Prev: JMatLink and new version of Matlab Next: interfacing rs232 (fread command) |