From: Steven Lord on

"dingz" <alexandertang357(a)hotmail.com> wrote in message
news:595447277.479086.1270052759993.JavaMail.root(a)gallium.mathforum.org...
> 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)');

Don't use an inline object here. Use an anonymous function.

z = @(x) exp(x).*(x.^i);

When you write an inline object like you did, MATLAB does NOT take the value
you've assigned to i into account when it evaluates the function -- it
treats it as sqrt(-1) [and this is consistent with the documentation.]

*snip*

--
Steve Lord
slord(a)mathworks.com
comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ


From: Steven Lord on

"dingz" <alexandertang357(a)hotmail.com> wrote in message
news:2092150558.479651.1270058166643.JavaMail.root(a)gallium.mathforum.org...
>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?

Yes, anonymous functions were introduced in MATLAB 7.0 (R14) and so can't be
used in version 6.5.

Take a look at the following document on our support website:

http://www.mathworks.com/support/solutions/data/1-1AIJF.html?solution=1-1AIJF

In the help for QUADL, you'll see a syntax that accepts parameters P1, P2,
etc. Those parameters are passed into your integrand function as additional
inputs. Using this, you can either write a 2-line function that accepts x
and i or write a two-input inline function and use QUADL with your i as the
P1 parameter.

--
Steve Lord
slord(a)mathworks.com
comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ