Thread Subject: How can I run this code?

Subject: How can I run this code?

From: alfann

Date: 2 Mar, 2010 12:55:37

Message: 1 of 3

could anyone guid me to run this code please?





function U=dirich(f1,f2,a,b,h,tol,max1);




n=fix(a/h)+1;
m=fix(b/h)+1;
ave=(a*(feval(f1,0)+feval(f2,0)))/(2*a);
U=ave*ones(n,m);

%Boundary Conditions
U(1,1:m)=feval(f3,0:h:(m-1)*h)';
U(n,1:m)=feval(f4,0:h:(m-1)*h)';
U(1:n,1)=feval(f1,0:h:(n-1)*h)';
U(1:n,m)=feval(f2,0:h:(n-1)*h)';
U(1,1)=(U(1,2)+U(2,1))/2;
U(1,m)=(U(1,m-1)+U(2,m))/2;
U(n,1)=(U(n-1,1)+U(n,2))/2;
U(n,m)=(U(n-1,m)+U(n,m-1))/2;

%SOR parameter
w=4/(2+sqrt(4-(cos(pi/(n-1))+cos(pi/(m-1)))^2));

%Refine approximations and sweep operator throughout the grid
err=1;
cnt=0;
while((err>tol)&(cnt<=max1))
    err=0;
    for j=2:m-1
        for i=2:n-1
            relx=w*(U(i,j+1)+U(i,j-1)+U(i+1,j)+U(i-1,j)-4*U(i,j))/4;
            U(i,j)=U(i,j)+relx;
            if (err<=abs(relx))
                err=abs(relx);
            end
        end
    end
    cnt=cnt+1;
end
U=flipud(U')








becuase I don't know about the method to run the "FUNCTION" in matlab...
Please help me...
I am waiting for everyone who like to help me.....

Subject: How can I run this code?

From: Prashant Sandhi

Date: 2 Mar, 2010 13:30:21

Message: 2 of 3

I have copied this code into 'Embedded MATLAB function block' and I would like to know what are the input here for 'f1,f2,a,b,h,tol,max1'?

This is how your code should look like i believe after removing three small mistakes in your code

1. Remove Semicolon in line one
2. while((err>tol)&(cnt<=max1)) is not valid I guess but with '&&' is valid
3. Add semicolon in the last line

alfann <alfann.net@hotmail.com> wrote in message <2044399501.297809.1267534567064.JavaMail.root@gallium.mathforum.org>...
> could anyone guid me to run this code please?
>
>
>
>
>
> function U=dirich(f1,f2,a,b,h,tol,max1);
>
>
>
>
> n=fix(a/h)+1;
> m=fix(b/h)+1;
> ave=(a*(feval(f1,0)+feval(f2,0)))/(2*a);
> U=ave*ones(n,m);
>
> %Boundary Conditions
> U(1,1:m)=feval(f3,0:h:(m-1)*h)';
> U(n,1:m)=feval(f4,0:h:(m-1)*h)';
> U(1:n,1)=feval(f1,0:h:(n-1)*h)';
> U(1:n,m)=feval(f2,0:h:(n-1)*h)';
> U(1,1)=(U(1,2)+U(2,1))/2;
> U(1,m)=(U(1,m-1)+U(2,m))/2;
> U(n,1)=(U(n-1,1)+U(n,2))/2;
> U(n,m)=(U(n-1,m)+U(n,m-1))/2;
>
> %SOR parameter
> w=4/(2+sqrt(4-(cos(pi/(n-1))+cos(pi/(m-1)))^2));
>
> %Refine approximations and sweep operator throughout the grid
> err=1;
> cnt=0;
> while((err>tol)&(cnt<=max1))
> err=0;
> for j=2:m-1
> for i=2:n-1
> relx=w*(U(i,j+1)+U(i,j-1)+U(i+1,j)+U(i-1,j)-4*U(i,j))/4;
> U(i,j)=U(i,j)+relx;
> if (err<=abs(relx))
> err=abs(relx);
> end
> end
> end
> cnt=cnt+1;
> end
> U=flipud(U')
>
>
>
>
>
>
>
>
> becuase I don't know about the method to run the "FUNCTION" in matlab...
> Please help me...
> I am waiting for everyone who like to help me.....

Subject: How can I run this code?

From: Steven Lord

Date: 2 Mar, 2010 14:23:14

Message: 3 of 3


"alfann" <alfann.net@hotmail.com> wrote in message
news:2044399501.297809.1267534567064.JavaMail.root@gallium.mathforum.org...
> could anyone guid me to run this code please?
>
> function U=dirich(f1,f2,a,b,h,tol,max1);

*snip*

> becuase I don't know about the method to run the "FUNCTION" in matlab...
> Please help me...
> I am waiting for everyone who like to help me.....

It sounds to me like you're new to MATLAB. If that's the case, I recommend
you read through the Getting Started section of the documentation and run
the examples you find in that section. That will explain how to work with
data and functions in MATLAB, and allow you to familiarize yourself with the
syntax. To open this section, type the following command at the MATLAB
prompt:

    doc

then open the MATLAB node in the tree on the left. Getting Started should
be one of the items underneath the MATLAB node.

After reading through that documentation, if you're still not sure how to
run this particular function, ask the person that gave it to you to add in
some help text comments to explain how to call it (and what the parameters
mean, etc.) and/or to explain to you how to use it.

--
Steve Lord
slord@mathworks.com
comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ

Tags for this Thread

Add a New Tag:

Separated by commas
Ex.: root locus, bode

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.

rssFeed for this Thread

Contact us at files@mathworks.com