Prev: ezplot & color
Next: Variable in Input Prompt
From: avi Marchavka on 23 Feb 2010 12:32 Advise needed, I have function of tree variables. Each has different domain. I need to integrate only over two of the variables. And then plot the result as function of the third variable. Thank you in advance Avi Simplify example ; [x,y,t]=meshgrid(0:.1:20,-2:1:100,0:.001:1); Function [z]=que(x,y,t) Z=x.*y.*t z1=quad2(@que,0,20,-2,100);
From: Steven Lord on 23 Feb 2010 13:20 "avi Marchavka" <avi.marchewka(a)gmail.com> wrote in message news:hm13f4$3he$1(a)fred.mathworks.com... > Advise needed, I have function of tree variables. Each has different > domain. I need to integrate only over two of the variables. And then plot > the result as function of the third variable. Thank you in advance > Avi > Simplify example ; > [x,y,t]=meshgrid(0:.1:20,-2:1:100,0:.001:1); > Function [z]=que(x,y,t) The keyword FUNCTION must be written all lower-case when used to define a function. I'm also assuming you're defining this function either in its own file or in a subfunction where the main function calls MESHGRID and then calls que. > Z=x.*y.*t > z1=quad2(@que,0,20,-2,100); Assuming this is a call to QUAD2D you do NOT want to call QUAD2D where the function handle that you specify as the first input is the same function where you're calling QUAD2D. If you called que as written, it would call QUAD2D which would call que which would call QUAD2D which would call que which would call QUAD2D which would call que which would call QUAD2D which would call que which would call QUAD2D ... you get the point. Anyway, you can either specify a fixed value for t in this situation (and I would use an anonymous function to do so.) t = 0:10; integral = zeros(size(t)); for k = 1:numel(t) integral(k) = quad2d(@(x, y) que(x, y, t(k)), 0, 20, -2, 100)); end Or you could integrate this expression symbolically using the INT function from Symbolic Math Toolbox. If you have this toolbox available, look at the HELP for that function. -- Steve Lord slord(a)mathworks.com comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ
|
Pages: 1 Prev: ezplot & color Next: Variable in Input Prompt |