help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Integration problem


From: James Sherman Jr.
Subject: Re: Integration problem
Date: Thu, 8 Jan 2009 17:26:15 -0500

While I don't have octave available currently, I believe your problem is that the quad function requires the first input to be a function of one input.  So, for a single u value it would look like:

>function y=int(x)
>y=sin(10.*x);
>endfunction;

Then the quad line should work.  Now if you want to dynamically change the u value, then you might do something like:

index = 1;
results = zeros(size([-10:0.1:10]));

for u = [-10:0.1:10]

   % creates the function as a string where the first input to int is the current value of u
   function_string = sprintf('int(%d, x)', u);

   % creates an inline function that only has one input 'x', because we want u to be constant.
   int_inline = inline(function_string, 'x');
  
   results(index) = quad('int_inline',0,2.*pi);

   index = index + 1;
end

There may be a better way to do this, but I think this should work.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]