function [q] = Eq27(Lg,x,r)
q = 0;
for k = 0:floor(x)
for l = 0:Lg-1
q =((-1^l)/(factorial(l)*factorial(k)))*nchoosek(Lg+k,k+l+1)*((r*(k-x))^(k+1))*exp(-1*r*(k-x));
end
end
q = ((1-r)^Lg)* q;
I define Lg, x, and r as symbolic variables in command prompt. However, I get this error message whenever I run Eq27(Lg,x,r):
??? Error using ==> sym.double at 25
DOUBLE cannot convert the input expression into a double array.
If the input expression contains a symbolic variable, use the VPA function instead.
Error in ==> sym.colon at 20
n = double((b-a)/d);
Error in ==> Eq27 at 3
for k = 0:floor(x)
Can you please help me to solve it?
syms Lg x r
"Matin Bagherpour" <mbagh...@yahoo.com> wrote in message <h8t1tr$1uu$1...@fred.mathworks.com>...
> I am trying to use Symbolic math tool to calculate this equation
>
> function [q] = Eq27(Lg,x,r)
syms Lg x r %try it here
Error in ==> sym.colon at 20
n = double((b-a)/d);
Error in ==> Eq27 at 4
for k = 0:floor(x)
It seems that I have to change definition of symbolic variables with subs or vpa function. But I don't know how.
"eematic ee" <eem...@att.net> wrote in message <h8t8cl$bp6$1...@fred.mathworks.com>...
You can't do a FOR loop over a symbolic expression if that expression
contains a symbolic variable. So for instance, this would work, since while
there is a symbolic expression involved that symbolic expression does not
contain a symbolic variable:
y = 0;
for k = 1:sym(12345)
y = y+1;
end
y
but this would not, since we can't tell how many times to iterate on the FOR
loop:
clear z
y = 0;
for k = 1:sym('z')
y = y+1;
end
y
If the expression you're using in the loop does contain some symbolic
variables, you must substitute in a value for those variables (using SUBS)
before trying to use it as a limit or increment in the FOR loop.
I've just checked and in release R2009b, the message that appears in the
latter situation has been made clearer:
>> clear z
y = 0;
for k = 1:sym('z')
y = y+1;
end
y
??? Error using ==> sym.colon at 27
Cannot compute the number of steps from 1 to z by 1.
--
Steve Lord
sl...@mathworks.com
comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ
"Steven Lord" <sl...@mathworks.com> wrote in message <h90ej0$ddo$1...@fred.mathworks.com>...
To make it easier to help you, can you show all the commands you made.
Starting from the console, what you typed, and how you called the function
Eq27() ?
This will make it easier for someone to repeat the same steps you made.
--Nasser
You could try using SYMSUM, but I would probably write my integrand function
so it accepts a numeric value for x and evaluates the integrand for that
value of x, then use QUADGK.
In the console I typed:
>> Delay38(0.6,0.7,1,0.5,1,2,0.7,0.5,1,0.2,1,0,0.7,0.5,1,0.5,1,2)
(some typical values for the inputs)
and received this message:
??? Error using ==> sym.double at 25
DOUBLE cannot convert the input expression into a double array.
If the input expression contains a symbolic variable, use the VPA function instead.
Error in ==> sym.colon at 20
n = double((b-a)/d);
Error in ==> Eq38 at 13
for k = 0:floor(x/b1)
Error in ==> Delay38 at 5
UR_1 = int(Eq38(v,rv1,rv2,bv1,bv2,nv1,nv2),'v',t-l,inf);
which seems that there is a problem with having a symbolic variable as FOR loop control variable.
I don't know how to use SUBS while as you can see from Delay38 that I need the first integration:
UR_1 = int(Eq38(v,rv1,rv2,bv1,bv2,nv1,nv2),'v',t-l,inf);
to be symbolic (a function of 't' and 'l') and be used in the second integration (a function of 't'):
First = int(Eq38(l,rl1,rl2,bl1,bl2,nl1,nl2).*Eq38(tl,ru1,ru2,bu1,bu2,nu1,nu2).*UR_1,'l',0,inf);
and finally in the third one:
ete = int(t.*(First + Second),'t',0,inf);
Could you please help me with it?
"Nasser Abbasi" <n...@12000.org> wrote in message <wQftm.16710$j34....@newsfe01.iad>...