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:
a function give two different results for the same params

Subject: a function give two different results for the same params

From: abdelmoumen

Date: 23 Dec, 2010 14:38:20

Message: 1 of 3

hello evrybody

i tried calculate this function for "s=0;" using "F_w(0)" i get a 9 columns result,
but the right result must be 3 columns.

if somebody try evalute this function by selcting the content and exucuting it using the
"Evaluate selection" option he get the right 3 column result.

please help me to know what's happend.

thank's
#########################################################################################
function f_w = F_w(s)
R = 100;
angle = (10:10:180)*pi/180;
L = angle(1)*R;
E = 10.5e6;
G = 4e6;
P = 100;
h = 2;
I = angle(1)*R^4/8;
A = pi*h^2/4;
k = 1;
a1 = R;
a2 = R;
a3 = R;
alpha = (E*I)/(G*A*k);
betha = I*R^2/A;

f1_w = (1/(16*R^3))*((csc(L/4*R)^2)*sec(L/4*R)*(4*(R^5)*cos(L/(4*R))-...
       betha*R*cos((3*L-4*s)/(4*R))-alpha*(R^3)*cos((3*L-4*s)/(4*R)))-...
       ((R^5)*cos((3*L-4*s)/(4*R))+2*betha*s*sin((3*L-4*s)/(4*R))+2*alpha*(R^2)*s*sin((3*L-4*s)/(4*R))+...
       2*(R^4)*s*sin((3*L-4*s)/(4*R))));

f2_w = (1/(16*R^3))*((csc(L/4*R)^2)*sec(L/4*R)*(4*(R^5)*cos(L/(4*R))-...
       betha*R*cos((L-4*s)/(4*R))-alpha*(R^3)*cos((L-4*s)/(4*R)))-...
       ((R^5)*cos((L-4*s)/(4*R))+2*betha*s*sin((L-4*s)/(4*R))+2*alpha*(R^2)*s*sin((L-4*s)/(4*R))+...
       2*(R^4)*s*sin((L-4*s)/(4*R))));

f3_w = (1/(8*R^3))*((csc(L/4*R)^2)*(-4*(R^5)*cos(L/(2*R))+...
       betha*R*cos((L-2*s)/(2*R))+alpha*(R^3)*cos((L-2*s)/(2*R)))+...
       ((R^5)*cos((L-2*s)/(2*R))+2*betha*s*sin((L-2*s)/(2*R))-2*alpha*(R^2)*s*sin((L-2*s)/(2*R))-...
       2*(R^4)*s*sin((L-2*s)/(2*R))));

f_w = [f1_w f2_w f3_w];
#########################################################################################

Subject: a function give two different results for the same params

From: Sean de

Date: 23 Dec, 2010 16:02:04

Message: 2 of 3

"abdelmoumen " <bmoumen27@yahoo.fr> wrote in message <ievmss$rim$1@fred.mathworks.com>...
> hello evrybody
>
> i tried calculate this function for "s=0;" using "F_w(0)" i get a 9 columns result,
> but the right result must be 3 columns.
>
> if somebody try evalute this function by selcting the content and exucuting it using the
> "Evaluate selection" option he get the right 3 column result.
>
> please help me to know what's happend.
>
> thank's
> #########################################################################################
> function f_w = F_w(s)
> R = 100;
> angle = (10:10:180)*pi/180;
> L = angle(1)*R;
> E = 10.5e6;
> G = 4e6;
> P = 100;
> h = 2;
> I = angle(1)*R^4/8;
> A = pi*h^2/4;
> k = 1;
> a1 = R;
> a2 = R;
> a3 = R;
> alpha = (E*I)/(G*A*k);
> betha = I*R^2/A;
>
> f1_w = (1/(16*R^3))*((csc(L/4*R)^2)*sec(L/4*R)*(4*(R^5)*cos(L/(4*R))-...
> betha*R*cos((3*L-4*s)/(4*R))-alpha*(R^3)*cos((3*L-4*s)/(4*R)))-...
> ((R^5)*cos((3*L-4*s)/(4*R))+2*betha*s*sin((3*L-4*s)/(4*R))+2*alpha*(R^2)*s*sin((3*L-4*s)/(4*R))+...
> 2*(R^4)*s*sin((3*L-4*s)/(4*R))));
>
> f2_w = (1/(16*R^3))*((csc(L/4*R)^2)*sec(L/4*R)*(4*(R^5)*cos(L/(4*R))-...
> betha*R*cos((L-4*s)/(4*R))-alpha*(R^3)*cos((L-4*s)/(4*R)))-...
> ((R^5)*cos((L-4*s)/(4*R))+2*betha*s*sin((L-4*s)/(4*R))+2*alpha*(R^2)*s*sin((L-4*s)/(4*R))+...
> 2*(R^4)*s*sin((L-4*s)/(4*R))));
>
> f3_w = (1/(8*R^3))*((csc(L/4*R)^2)*(-4*(R^5)*cos(L/(2*R))+...
> betha*R*cos((L-2*s)/(2*R))+alpha*(R^3)*cos((L-2*s)/(2*R)))+...
> ((R^5)*cos((L-2*s)/(2*R))+2*betha*s*sin((L-2*s)/(2*R))-2*alpha*(R^2)*s*sin((L-2*s)/(2*R))-...
> 2*(R^4)*s*sin((L-2*s)/(2*R))));
>
> f_w = [f1_w f2_w f3_w];
> #########################################################################################

I get the same result every time, as I would expect:
%{
f_w = 1.3957e+06 1.4066e+06 2.6384e+06
%}

Subject: a function give two different results for the same params

From: abdelmoumen

Date: 23 Dec, 2010 16:17:05

Message: 3 of 3

i dont know what happend with matlab, because when i changed the file directory i get the right result.

thank you for your effort

Tags for this Thread

No tags are associated with 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