I'm writing a program in MuPAD. In this I'm using an equation which contains summation as well as product of N terms. But on running the code MuPAD throws an error:
Error: The summation variable must be an identifier or indexed identifier. [sum]
Can anyone suggest something? Thanks in advance. Below is my entire code.In this i am getting error in the second last line.
N:= 2;
lamda:= 785*10^(-9);
d:= 1*10^3;
a:= 5*10^-2;
ap:= 10;
be:=5;
bo:=0.25;
rhom:= 0.95;
g:= 2*bo*(1-rhom);
ohm:= 0.5;
f:= ohm + 2*(bo)*rhom;
A:= ((2*(ap)^(ap/2))/((g^(1+(ap/2)))*gamma(ap)))*(((g*be)/(g*be+f))^(be+(ap/2)));
k:= 2*PI/lamda;
ak:= (binomial(be-1,k-1)/gamma(k))*((g*be+f)^(1-(k/2)))*((f/g)^(k-1))*(ap/be)^(k/2);
ad:= 0.6;
v:= (sqrt(PI)*a)/(sqrt(2)*ad);
ae:= float(sqrt((ad^2*sqrt(PI)*erf(v))/(2*v*exp(-v^2))));
sigmas:= 0.3;
z:= ae/(2*sigmas);
sk:=(z^2/(1+z^2));
Y:=(ap^2*be^2*sk^2*(g+f)^2)/(16*ui*((g*be)+f)^2);
ccc:= meijerG(5,1,[1,(2+z^2)/2],[z^2/2,ap/2,(1+ap)/2,k/2,(1+k)/2],Y);
X:= (((ap*be)/(g*be+f))^(-((ap+k)/2)));
pb:=(1/2)*product(numeric::sum(((z^2*A*ak*(2^(ap+k-4)))/PI)*X*ccc,k=1..be),i=1..N);
S2:=hfarray(1..3,[pb $ ui=1..3]);
The summation variable name k is already used here: k:= 2*PI/lamda. Changing to a different variable name fixes the error.
Related
I am trying to get list of all the authors who have had 3 or more piece of work done (in DBpedia).
my example can be run on : http://dbpedia.org/sparql
base code
select (count(?work) as ?totalWork), ?author
Where
{
?work dbo:author ?author.
}
GROUP BY ?author
I get each authors total amount of piece of work done. But when I try to filter to show only list of author that have more than 3 piece of work. I get error:
I tried HAVING keyword or using FILTER keyword.
Using Filter
select (count(?work) as ?tw), ?author
Where
{
?work dbo:author ?author.
FILTER (?work > 3).
}
GROUP BY ?author
error: Virtuoso 22023 Error VECDT: SR066: Unsupported case in CONVERT (INTEGER -> IRI_ID)
Using HAVING keyword
select (count(?work) as ?tw), ?author
Where
{
?work dbo:author ?author.
}
GROUP BY ?author
HAVING (?tw > 3)
Virtuoso 37000 Error SP031: SPARQL compiler: Variable ?tw is used in the result set outside aggregate and not mentioned in GROUP BY clause
Using HAVING is correct, but there is a limitation in SPARQL with indirectly referring to aggregates.
This one works:
SELECT (count(?work) as ?tw) ?author
WHERE
{
?work dbo:author ?author.
}
GROUP BY ?author
HAVING (count(?work) > 3)
HAVING (?tw > 3) is correct SPARQL. HAVING filters after assignments due to SELECT, so ?tw is visible, and before projection.
(prefix ((dbo: <http://purl.org/dc/elements/1.1/>))
(project (?tw ?author)
(filter (> ?tw 3)
(extend ((?tw ?.0))
(group (?author) ((?.0 (count ?work)))
(bgp (triple ?work dbo:author ?author)))))))
where ?.0 is the assignment of count.
I am having trouble with is line "P_dot_ij_om_+ii(i,1)=P_dot_ij(k,2);"
basically I have declared matrix P_dot_ij_om_1=[] from 1 to i
and in the next line.
I would like to input data e.g. P_dot_ij_om_+ii(i,1)=P_dot_ij(k,2);
where ii is a number. what is the right expression.
rows=round(k/360);
i=1;
ii=1;
k=1;
while ii <= rows
Pdot_names(ii,1)=string("P_dot_ij_om_"+ string(ii));
disp(Pdot_names(ii))
execstr(Pdot_names(ii)+'=[]'); // declare indexed matrix
while i<361
P_dot_ij_om_+ii(i,1)=P_dot_ij(k,2);
// P_dot_ij_om_+ii(i,2)=P_dot_ij(k,3);
disp(k)
k=k+1;
i=i+1;
end
ii=ii+1;
end
The code below works, but in general it is not advised to create string variables. There are much faster and also easier to implement alternatives, see e.g. this thread: How can I create variables Ai in loop in scilab, where i=1..10
rows = 2;
P_dot_ij = [10,20,30;11,21,31;12,22,32];
i=1;
ii=1;
k=1;
while ii <= rows
//Pdot_names(ii,1)=string("P_dot_ij_om_"+ string(ii)); The firs 'string' is unnecessary
Pdot_names(ii,1)="P_dot_ij_om_"+string(ii);
disp(Pdot_names(ii))
execstr(Pdot_names(ii)+'=[]'); // declare indexed matrix
while i<4
//P_dot_ij_om_+ii(i,1)=P_dot_ij(k,2);
execstr("P_dot_ij_om_"+string(ii)+"("+string(i)+",1)=P_dot_ij("+string(k)+",2)"); // P_dot_ij_om_+ii(i,2)=P_dot_ij(k,3);
execstr("P_dot_ij_om_"+string(ii)+"("+string(i)+",2)=P_dot_ij("+string(k)+",3)");
disp(k)
k=k+1;
i=i+1;
end
ii=ii+1;
end
disp(P_dot_ij_om_1,"P_dot_ij_om_1");
disp(P_dot_ij_om_1,"P_dot_ij_om_2");
And also next time please post selfcontained code examples, because otherwise I can only guess what is k and P_dot_ij.
This is trivial in mysql thanks to mysql_num_rows but no such equivalent is present in sqlite3. Hence the question is how to know if the current row is the last row.
Rearranging like following doesn't help as any previous binding after sqlite3_step is not valid.
sqlite3_prepare_v2()
int fetched = 0;
int last = 0;
while (sqlite3_step(statement) == SQLITE_ROW) {
// this is the previous row
if(fetched) {
process(data, last);
}
fetched = 1;
data = sqlite3_column_text();
}
last = 1;
if(fetched)
process(data, last);
Executing query twice (one with count) is a trivial solution but that's not what I am looking for.
Any ideas? thanks in advance.
SQLite computes the next output row only when needed.
So it is not possible to find out if you can get another row without actually trying to step to that row.
If your code really needs to know whether the current row is the last, you have to make a copy of all the data in the row.
I try to create a loop that will create data frames by using different sql queries that have the same name exept the day number.For example here is the name for query that is for day 1 :SF_2013_Day1_BaseLine and this is for day 6: SF_2013_Day6_BaseLine. I wrote this code (below) but I got an error : Error: unexpected ',' in "for(i in 3," .So any Idea how can i get this code to work ?
Thank you
for (i in 1,3,6,10,14,21,30) {
SF_FinalviewQ3_2013_Day[i]_BaseLine<-sqlQuery(DB,"select * from [SF_2013_Day[i]_BaseLine]");
dim(SF_Day[i]_BaseLine)}
After a change based on #Pgibas edvice to this code :
for (i in c(1,3,6,10,14,21,30)) {
SF_FinalviewQ3_2013_Day[i]_BaseLine<-sqlQuery(DB,"select * from [SF_2013_Day[i]_BaseLine]");
dim(SF_Day[i]_BaseLine)}
I got this error: Error: unexpected input in "for(i in c(3,6)){glm_d[i]_" . What can I do to resolve the problem?
You need to resolve i within the names first:
for (i in c(1,3,6,10,14,21,30)) {
set <- sqlQuery(DB, paste0("select * from [SF_2013_Day[", i, "]_BaseLine]"))
eval(parse(text = paste0("SF_FinalviewQ3_2013_Day", i, "_BaseLine <- set"))
dim(set)
}
I wrote the codes in Modelica as below:
model TestIniitial
extends Modelica.Icons.Example;
parameter Integer nWri= 2;
Real u[nWri](each start= 10, fixed=false);
Real uPre[nWri];
parameter Real _uStart[nWri] = fill(10, nWri);
parameter Modelica.SIunits.Time startTime = 0;
parameter Modelica.SIunits.Time samplePeriod = 1;
Boolean sampleTrigger "True, if sample time instant";
initial equation
u[1] = 1;
u[2] = 2;
equation
sampleTrigger = sample(startTime, samplePeriod);
when sampleTrigger then
for i in 1: nWri loop
uPre[i] = pre(u[i]);
end for;
end when;
for i in 1:nWri loop
u[i] = (i+1)*time;
end for;
end TestIniitial;
Basically I want to initialize the u before simulation. However, I got below complaints(the initialization of u is over-specified) from translation:
The Modelica Language Specification 3.2.1 specifies that if a real variable, v,
is appearing in an expression as pre(v), but not assigned by a when equation,
then the equation v = pre(v) should be added to the initialization problem.
For this problem the following equations were added:
u[1] = pre(u[1]);
u[2] = pre(u[2]);
I can't understand the complaints since pre(v) was assigned in when equation already. What can I do if I want to initialize the u in above codes?
Thanks.
Looking at this, my guess is that the error message is trying to provide you some diagnostics but it is incorrect about the source. I suspect (again, I do not know for sure) that it sees the fact that pre(u) appears in the model and that there is an initialization problem and assumes a specific issue.
My guess is that the issue stems from the fact that you have fixed=true set on u. I see no reason to do that and my guess is that it will lead to too many constraints on the initialization problem as well. Get rid of the fixed=true and see what happens. Report back if that doesn't address the problem.
Good luck.