Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
problem on quad

Subject: problem on quad

From: Azrul

Date: 10 Apr, 2010 07:38:08

Message: 1 of 9

hi all,

i am currently doing an analysis on suspension system but faces problem regarding the quad function ..

the main body is :

global m mw k kt c u s
m =250; %kg
mw=37.5; %kg
k =20000; %N/m
kt=200000; %N/m
c =1120; %Ns/m
u=10;

Q=quad(@myfunacc,1, 25);
---------------------------------------------------------------------------------------------------------------------
the function is :

function y = myfunacc(x)

global m mw k kt c u s

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;

RMSacc=(omega^2)*x1;

y=((abs(RMSacc))^2).*(256E-6).*(0.1.^2).*(u./(x.^2));
------------------------------------------------------------------------------------------------------------------
i've also try y=((abs(RMSacc))^2)*(256E-6)*(0.1^2)*(u/(x^2));

but both gives me an error :

??? Input argument "a" is undefined.

Error in ==> quad at 69
if ~isscalar(a) || ~isscalar(b)
-------------------------------------------------------------------------------------------------------------

the program should give me a scalar value. i am not sure what is wrong . i am new with matlab and hope someone can help me .. thanks
 

Subject: problem on quad

From: Roger Stafford

Date: 10 Apr, 2010 09:17:09

Message: 2 of 9

"Azrul " <azrul.afifi@gmail.com> wrote in message <hpp9t0$ikr$1@fred.mathworks.com>...
> hi all,
>
> i am currently doing an analysis on suspension system but faces problem regarding the quad function ..
>
> the main body is :
>
> global m mw k kt c u s
> m =250; %kg
> mw=37.5; %kg
> k =20000; %N/m
> kt=200000; %N/m
> c =1120; %Ns/m
> u=10;
>
> Q=quad(@myfunacc,1, 25);
> ---------------------------------------------------------------------------------------------------------------------
> the function is :
>
> function y = myfunacc(x)
>
> global m mw k kt c u s
>
> 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;
>
> RMSacc=(omega^2)*x1;
>
> y=((abs(RMSacc))^2).*(256E-6).*(0.1.^2).*(u./(x.^2));
> ------------------------------------------------------------------------------------------------------------------
> i've also try y=((abs(RMSacc))^2)*(256E-6)*(0.1^2)*(u/(x^2));
>
> but both gives me an error :
>
> ??? Input argument "a" is undefined.
>
> Error in ==> quad at 69
> if ~isscalar(a) || ~isscalar(b)
> -------------------------------------------------------------------------------------------------------------
>
> the program should give me a scalar value. i am not sure what is wrong . i am new with matlab and hope someone can help me .. thanks
---------------
  The 'quad' function requires that the function it calls on be able to accept a vector of values rather than just a single scalar. It is part of its strategy to help minimize the time spent calling repetitively on the integrand function. The Mathworks description for 'quad' says, "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."

  Where you write such things as "omega^4" these will not compute properly with a vector 'omega'. You need to say "omega.^4" instead. Similarly in the x1 computation with "/A" - it should be "./A", and also in (omega^2)*x1 there should be ".*' and ".^".

Roger Stafford

Subject: problem on quad

From: John D'Errico

Date: 10 Apr, 2010 13:59:26

Message: 3 of 9

"Azrul " <azrul.afifi@gmail.com> wrote in message <hpp9t0$ikr$1@fred.mathworks.com>...
> hi all,
>
> i am currently doing an analysis on suspension system but faces problem regarding the quad function ..
>
> the main body is :
>
> global m mw k kt c u s
> m =250; %kg
> mw=37.5; %kg
> k =20000; %N/m
> kt=200000; %N/m
> c =1120; %Ns/m
> u=10;
>
> Q=quad(@myfunacc,1, 25);
> ---------------------------------------------------------------------------------------------------------------------
> the function is :
>
> function y = myfunacc(x)
>
> global m mw k kt c u s
>
> 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;
>
> RMSacc=(omega^2)*x1;
>
> y=((abs(RMSacc))^2).*(256E-6).*(0.1.^2).*(u./(x.^2));
> ------------------------------------------------------------------------------------------------------------------
> i've also try y=((abs(RMSacc))^2)*(256E-6)*(0.1^2)*(u/(x^2));
>
> but both gives me an error :
>
> ??? Input argument "a" is undefined.
>
> Error in ==> quad at 69
> if ~isscalar(a) || ~isscalar(b)
> -------------------------------------------------------------------------------------------------------------
>
> the program should give me a scalar value. i am not sure what is wrong . i am new with matlab and hope someone can help me .. thanks
>

The error message input argument a is undefined suggests
that you have named a script by the name quad.m. So
when you try to run the script quad, that then calls quad,
matlab has difficulty in knowing which quad you are trying
to use. Do not name your scripts with the names of
existing and useful tools in matlab. This will cause many
problems for you.

Try this:

which quad -all

HTH,
John

Subject: problem on quad

From: Azrul

Date: 12 Apr, 2010 15:20:21

Message: 4 of 9

thanks for both solutions. it works :) .. actually, my problem is to plot the graph y vs c .. in other words, instead of setting c=1120, i should have a loop for c like c=[800:20:2000] so that i can identify which value of c gives me the best y .. i have tried to browsed around but could not find the similar problem .. thanks in advance

Subject: problem on quad

From: Azrul

Date: 12 Apr, 2010 15:42:05

Message: 5 of 9

here is my new script ..

function y = myfunacc(x,c)

and for the main body

for c=600:2000
RMSacc(c)=quadv(@(x)myfunacc(x,c),0.01,25);

--------------------------------------------------------------------------------------------------------------

i followed one of the example in matlab .. but as ususal, it failed

??? Error: File: integration.m Line: 10 Column: 1
At least one END is missing: the statement may begin here.
 
please help me .. thanks in advance

Subject: problem on quad

From: John D'Errico

Date: 12 Apr, 2010 15:51:04

Message: 6 of 9

"Azrul " <azrul.afifi@gmail.com> wrote in message <hpvf0c$kn1$1@fred.mathworks.com>...
> here is my new script ..
>
> function y = myfunacc(x,c)
>
> and for the main body
>
> for c=600:2000
> RMSacc(c)=quadv(@(x)myfunacc(x,c),0.01,25);
>
> --------------------------------------------------------------------------------------------------------------
>
> i followed one of the example in matlab .. but as ususal, it failed
>
> ??? Error: File: integration.m Line: 10 Column: 1
> At least one END is missing: the statement may begin here.
>
> please help me .. thanks in advance

Note that a for loop must be terminated by an end
statement.

help for

What does the error message say? There is a missing
end statement.

Read the error messages. They are issued for a reason.

John

Subject: problem on quad

From: Azrul

Date: 12 Apr, 2010 16:37:04

Message: 7 of 9

sorry .. its not that as usual it failed .. but as usual, i cannot do it .. thanks for ur help

Subject: problem on quad

From: Azrul

Date: 15 Apr, 2010 12:17:04

Message: 8 of 9

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

Subject: problem on quad

From: Michael Hosea

Date: 16 Apr, 2010 15:46:42

Message: 9 of 9

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

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us