|
View:
New views
11 Messages
—
Rating Filter:
Alert me
|
|
|
Integration problemHi,
Why it does not work? >u=[-10:0.1:10]; >function y=int(u,x) >y=sin(u.*x); >endfunction; >y=quad("int",0,2.*pi); I would like to plot such a function: f(u)=\int_{0}^{2\pi}sin(ux)dx Any idea how to do it? Thanks for help. MS |
|
|
Re: Integration problemWhile 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. _______________________________________________ Help-octave mailing list Help-octave@... https://www-old.cae.wisc.edu/mailman/listinfo/help-octave |
|
|
Re: Integration problemOn Thu, Jan 8, 2009 at 10:14 PM, Marcin Sleczka <marcin.sleczka@...> wrote:
> > Hi, > Why it does not work? >>u=[-10:0.1:10]; >>function y=int(u,x) >>y=sin(u.*x); >>endfunction; > >>y=quad("int",0,2.*pi); > > I would like to plot such a function: > f(u)=\int_{0}^{2\pi}sin(ux)dx > > Any idea how to do it? > > Thanks for help. > MS Hi if you use quad, the function you integrate must accept one scalar argument, while your function accepts two arguments (so one of them is undefined when it is called form quad). To compute your function, I would try something like this: u = -10:0.01:10; function r = f(u) % f(u)=\int_{0}^{2\pi}sin(ux)dx for i=1:length(u) intfun = @(x) sin(u(i)*x); r(i) = quad(intfun,0,2*pi); end end plot (u,f(u)) Regards Ivan Sutoris _______________________________________________ Help-octave mailing list Help-octave@... https://www-old.cae.wisc.edu/mailman/listinfo/help-octave |
|
|
Re: Integration problemOn 8-Jan-2009, James Sherman Jr. wrote:
| 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. Using an anonymous function is a bit simpler: rng = -10:0.1:10; results = zeros (size (rng)); idx = 1; for u = rng results(idx++) = quad (@(x) sin(u*x), 0, 2*pi); endfor jwe _______________________________________________ Help-octave mailing list Help-octave@... https://www-old.cae.wisc.edu/mailman/listinfo/help-octave |
|
|
Re: Integration problem
Hi, What means "@(x)" I can't find it? How can I learn octave? Is there any online course? I don't want to ask for help all the time :-) Thanks MS |
|
|
Re: Integration problemFor a quick explanation of what "@(x)" does:
Anonymous Function I don't know of any particular course for learning octave, but the This is a good online reference document. _______________________________________________ Help-octave mailing list Help-octave@... https://www-old.cae.wisc.edu/mailman/listinfo/help-octave |
|
|
Re: Integration problemI found that I can't integrate complex function with use quad. What if int will be complex function? |
|
|
Re: Integration problem> How can I learn octave? Is there any online course? I don't want to
> ask for help all the time :-) Have you looked at the manual? It needs some work to make it a good reference. Since you are a newcomer, you could not where it needs improvement, and possibly start improving it yourself. -- Francesco Potortì (ricercatore) Voice: +39 050 315 3058 (op.2111) ISTI - Area della ricerca CNR Fax: +39 050 315 2040 via G. Moruzzi 1, I-56124 Pisa Email: Potorti@... (entrance 20, 1st floor, room C71) Web: http://fly.isti.cnr.it/ _______________________________________________ Help-octave mailing list Help-octave@... https://www-old.cae.wisc.edu/mailman/listinfo/help-octave |
|
|
Re: Integration problemI found that I can't integrate complex function with use quad. What if int will be complex function? Please tell me how to do it? |
|
|
Re: Integration problem2009/1/10 Marcin Sleczka <marcin.sleczka@...>:
> > > > I found that I can't integrate complex function with use quad. What if int > will be complex function? Same way you integrate any other complex function... you turn it into a real one. What complex function are you integrating anyways? A line integral? Parametrise the curve and integrate along the real parameter. _______________________________________________ Help-octave mailing list Help-octave@... https://www-old.cae.wisc.edu/mailman/listinfo/help-octave |
|
|
Re: Integration problemJordi Gutiérrez Hermoso wrote:
> 2009/1/10 Marcin Sleczka <marcin.sleczka@...>: > >> >> I found that I can't integrate complex function with use quad. What if int >> will be complex function? >> > > Same way you integrate any other complex function... you turn it into > a real one. > > What complex function are you integrating anyways? A line integral? > Parametrise the curve and integrate along the real parameter. > _______________________________________________ > Help-octave mailing list > Help-octave@... > https://www-old.cae.wisc.edu/mailman/listinfo/help-octave > > integrals. You can take this function from 3.1.x and use it with 3.0.3 without problems D. -- David Bateman dbateman@... 35 rue Gambetta +33 1 46 04 02 18 (Home) 92100 Boulogne-Billancourt FRANCE +33 6 72 01 06 33 (Mob) _______________________________________________ Help-octave mailing list Help-octave@... https://www-old.cae.wisc.edu/mailman/listinfo/help-octave |
| Free embeddable forum powered by Nabble | Forum Help |