|
I have not looked at your functions. However, since there is some question
here about vectorization, I would suggest using ARRAYFUN until you are sure
your integrand returns the right value for a given input. Instead of
quad(@myfun,a,b)
write
quad(@(x)arrayfun(@myfun,x),a,b)
ARRAYFUN will call your function only with scalar inputs, so you can forget
about vectorization issues with .^ and such. Once you get that working
properly, then move on to vectorizing the integrand for better performance.
--
Mike
"Azrul " <azrul.afifi@gmail.com> wrote in message
news:hq7040$sg4$1@fred.mathworks.com...
> hello, the program works .. but the problem is its giving me the wrong
> answer .. i run the quad with 3 different function ie.
> RMSacc=quad(@myfunacc,0.01,25)
> RMSsus=quad(@myfunsus,0.01,25)
> RMSforce=quad(@myfunforce,0.01,50,1E-9)
>
> what concerned me is that RMSacc gave me the predicted value while the
> other 2 give me the wrong value .. ie
> RMSsus = 6.4216e-005 when the predicted value should be around 0.005 -
> 0.01
>
> RMSforce = 3.4846e+005 when the predicted value is
> 500-1000 ----------------------------------------------------------------------------------------------------------------
> the function for RMSforce is :
>
> jot = sqrt(-1);
>
> omega=2*pi*x;
>
> A= ((omega.^4)*m*mw)-((omega.^2)*(k*mw+k*m+kt*m))+(k*kt)-((omega.^3)*
> (c*mw*jot+c*m*jot))+(c*kt*omega*jot) ;
>
> x2=((((-omega.^2)*m)+k+(c*omega*jot))*kt)./A;
>
> FRFforce=abs(kt*(x2-1));
>
> f=((FRFforce.^2)*256E-6*(0.1.^2)*u)./(x.^2);
> -------------------------------------------------------------------------------------------------------------------
> and RMSsus is :
>
> function z = myfunsus(x)
>
> global m mw k kt u s c
>
> jot = sqrt(-1);
>
> omega=2*pi*x;
>
> A= ((omega.^4)*m*mw)-((omega.^2)*(k*mw+k*m+kt*m))+(k*kt)-((omega.^3)*
> (c*mw*jot+c*m*jot))+(c*kt*omega*jot) ;
>
> x1=((k+(c*jot*omega))*kt)./A;
> x2=((((-omega.^2)*m)+k+(c*omega*jot))*kt)./A;
>
> FRFsus=abs((x1)-(x2));
>
> z=((FRFsus.^2)*256E-6*(0.1.^2)*u)./(x.^2);
> -----------------------------------------------------------------------------------------------------------------------
>
> i have showed to my tutor about this and he said that the dot ie.
> ((omega.^4)) etc should not be there since the dot make the program run
> with many omega whereas i only need one omega .. but, as we discussed
> earlier, we should include the dot to run quad .. is there any way to fix
> this coz i have tried to run it with or without dot and can's seem to find
> the answer .. p/s: the formula of "A" and "x1"is right since it works for
> RMSacc .. problem at "x2","FRFsus" or "FRFforce" where i should/shouldnt
> put dot maybe? .. thanks
|