PDA

View Full Version : Some Matlab technical programming problem


kubekas
Jul17-09, 03:39 AM
Hi there every one

I need some help with the following function:

function cc = find_cc(n)
global nu
cc(1)=(-8.*i.*nu1-3.*n.^2-5+4.*i.*nu1.*n-4.*n)./n./(-n-2+4.*i.*nu1);
cc(2)=(3.*n.^2+2.*n+4)./n./(-n-2+4.*i.*nu1);
cc(3)=-(n-1).*(n+1)./n./(-n-2+4.*i.*nu1);
end
where

\nu is abitrary variable. cc(1), cc(2) and cc(3) are entries of a cc(3,1) matrix. Each time I run the above function I get the following message:

"In an assignment A(I) = B, the number of elements in B and
I must be the same"

I guess the problem here is \nu because if I set \nu to 1 the it works. But I want \new to be abbitrary. The above function is called by this function
function vs=reg_series(s)
global nu;
cc1=find_cc(1);
cc2=find_cc(2);
cc3=find_cc(3);
aa0=1;
aa(1)=aa0*cc1(1);
aa(2)=aa0*cc2(2)+aa(1)*cc2(1);
aa(3)=aa0*cc3(3)+aa(1)*cc3(2)+aa(2)*cc3(1);
sn=s.^3;
ss=aa0+aa(1).*s+aa(2).*s.^2+aa(3).*s.^3;
dss_ds=aa(1)+2.*s.*aa(2)+3.*s.^2.*aa(3);
asn=ones(length(s));
nn=4;
while ((abs(nn*asn(length(asn)))>1e-18) && (nn<500))
cct=find_cc(nn);
aa(nn)=aa(nn-1)*cct(1)+aa(nn-2)*cct(2)+aa(nn-3)*cct(3);
dss_ds=dss_ds+sn.*nn*aa(nn);
sn=s.*sn;
asn=aa(nn).*sn;
ss=ss+asn;
nn=nn+1;
end
dss_dz=-2*dss_ds;
vs=ss./dss_dz;
end


to generate a series with \nu as abitrary function. If I use "syms" on to keep \nu as a variables in the function cc = find_cc(n) above, then function vs=reg_series(s) is given me the following error message after the second last end command

"Function 'gt' is not defined for values of class 'sym'."

ANY HELP GUYS?
Amos

trambolin
Jul17-09, 04:45 AM
Your code is really cumbersome and you can get rid of .* products if you use scalars.

The first error happens when you want to assign a vector to a single index e.g.

A(1) = [3 4]

Second one I don't know becuse there is no 'gt' function appearing in your code.

kubekas
Jul17-09, 05:09 AM
Thank you Trambolin for the reply. But are you implying that I should then redefine the matrix entries to be vectors?

CEL
Jul17-09, 09:42 AM
You pass the variable n as an argument of the function and you have the variable nu declared as global, but you use a variable nu1 in your function.
If cc is a matrix, to adress its first line you must write cc(1,:) and not cc(1).

kubekas
Jul17-09, 10:50 AM
Sorry CEL, I meant nu not nu1. Also cc is meant to be a vector.