From: Didi Cvet on 2 Nov 2009 08:27 Hello everyone I use quad functions to evaluate the integral value of my function: >> function y=el_en1(s,C) Cprim=fnder(C); ff=fnval(C, s); ff1=fnval(Cprim, s); Csek=fnder(Cprim); ff2=fnval(Csek, s); cprim_norm=sqrt(ff1(1,:).^2+ff1(2,:).^2); kk=abs(ff'*ff2)/(abs(ff1)).^3; yy=(kk.^2)'*cprim_norm'; y=sqrt(yy(1,:)^2+yy(2,:)^2); >> but every time when I coll quadgk (or any quad function) >> quadgk(@(s) el_en1(s, C0), 0, 1) >> I get this error message: ??? Error using ==> quadgk>finalInputChecks at 488 Output of the function must be the same size as the input. Error in ==> quadgk>evalFun at 365 finalInputChecks(x,fx); Error in ==> quadgk>f1 at 382 [y,too_close] = evalFun(tt); Error in ==> quadgk>vadapt at 276 [fx,too_close] = f(x); Error in ==> quadgk at 215 [q,errbnd] = vadapt(@f1,interval); Can anyone help me? What does this mean and please any suggestions how can I fix it? Thanks Dijana
From: Steven Lord on 2 Nov 2009 09:07 "Didi Cvet" <didi_cvet(a)yahoo.com> wrote in message news:hcmmn6$m97$1(a)fred.mathworks.com... > Hello everyone > I use quad functions to evaluate the integral value of my function: > >>> > function y=el_en1(s,C) > Cprim=fnder(C); > ff=fnval(C, s); > ff1=fnval(Cprim, s); > Csek=fnder(Cprim); > ff2=fnval(Csek, s); > cprim_norm=sqrt(ff1(1,:).^2+ff1(2,:).^2); > kk=abs(ff'*ff2)/(abs(ff1)).^3; > yy=(kk.^2)'*cprim_norm'; > y=sqrt(yy(1,:)^2+yy(2,:)^2); >>> > > but every time when I coll quadgk (or any quad function) > >>> > quadgk(@(s) el_en1(s, C0), 0, 1) >>> > > I get this error message: > ??? Error using ==> quadgk>finalInputChecks at 488 > Output of the function must be the same size as the input. That's correct. From the reference page for QUADGK: http://www.mathworks.com/access/helpdesk/help/techdoc/ref/quadgk.html "The function y = fun(x) should accept a vector argument x and return a vector result y. The integrand evaluated at each element of x." [And yes, I'll ask our documentation staff to fix this.] What happens if you call your function with a vector s and the C0 you refer to in your anonymous function "adapter"? Does it return a vector the same size as your input vector? If not, you need to fix your function so it does. -- Steve Lord slord(a)mathworks.com comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ
From: Michael Hosea on 2 Nov 2009 16:06 "Steven Lord" <slord(a)mathworks.com> wrote in message news:hcmp1u$jcs$1(a)fred.mathworks.com... > What happens if you call your function with a vector s and the C0 you refer > to in your anonymous function "adapter"? Does it return a vector the same > size as your input vector? If not, you need to fix your function so it > does. Yes, and we should mention that ARRAYFUN is a reasonable, if not so efficient, way of getting it working. For example, if there are no other errors to deal with, then this should work: quadgk(@(t) arrayfun(@(s)el_en1(s, C0),t), 0, 1) If performance is a problem, then I would try to vectorize el_en1. -- Mike
From: Didi Cvet on 3 Nov 2009 04:08 "Michael Hosea" <Michael.Hosea(a)mathworks.com> wrote in message <hcnhjs$ajf$1(a)fred.mathworks.com>... > > "Steven Lord" <slord(a)mathworks.com> wrote in message > news:hcmp1u$jcs$1(a)fred.mathworks.com... > > What happens if you call your function with a vector s and the C0 you > refer > > to in your anonymous function "adapter"? Does it return a vector the same > > size as your input vector? If not, you need to fix your function so it > > does. > > Yes, and we should mention that ARRAYFUN is a reasonable, if not so > efficient, way of getting it working. For example, if there are no other > errors to deal with, then this should work: > > quadgk(@(t) arrayfun(@(s)el_en1(s, C0),t), 0, 1) > > If performance is a problem, then I would try to vectorize el_en1. > -- > Mike > Thanks tor you reply I tried as you suggest - with arrayfun, but it takes fairly much time to compute it and if I considerate that I take this integral as objective function in fmincon it works really much time so I guess I'll try to make my function to return a vector. Thanks anyway Didi
|
Pages: 1 Prev: Waiting on C++ routine to finish Next: help, errore che mi fa impazzire |