help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Getting started with functions


From: Geordie McBain
Subject: Re: Getting started with functions
Date: Thu, 01 Jun 2006 10:25:01 +1000

Hello.  The Octave function quad is only really designed for functions
of one variable; however, you can get around this by using global
variables.  In your case, define the functions
---
function y = barnes_F (phi)
  global a
  global z
  global R
  y = (1-a./R*cos(phi))./(a./R^2+z./R^2+1-2*a./R*cos(phi)).^1.5;
endfunction
---
function h = barnes_Hz (I, R1, a1, z1)
  global a
  global z
  global R
  a = a1; z = z1; R = R1;
  h = quad ("barnes_F", 0, 2*pi); # 6.28 is 2*pi, right?
endfunction
---
then:

---
octave> barnes_Hz (1, 1, 1, 1)
ans = 0.96483
octave> 
---

Is that the right answer?

By the way, the formula for F looks dimensionally suspect: should the
first a and z in the denominator be squared to match the R^2?

Hope that helps.

Geordie McBain
www.aeromech.usyd.edu.au/~mcbain


On Wed, 2006-05-31 at 14:44 -0300, Andrew Barnes wrote:
> I'm trying the model a solonoid and the first thing I want to do is get
> Octave to calculate the field due to a single loop.
> 
> I have the following code in a function but it does not work.  Any help
> would be appreciated.
> 
> 
> ## I is the current
> ## R is the radius
> ## a is the radus at which we want to know the field strength
> ## z is the height relative to the loop.
> function Hz = hz_single_loop(I,R,a,z)
>       F = @(phi) (1-a./R*cos(phi))./(a./R^2+z./R^2+1-2*a./R*cos(phi)).^1.5;
>       Hz = I./(4*pi*R).*quad(F,0,6.28);
> endfunction
> 
> I'm having trouble setting started in Octave.  I'm finding the learing curve
> steep.
> 
> ====================================
> Andrew Barnes P.Eng
> AMIRIX Systems Inc.
> 77 Chain Lake Drive
> Halifax, Nova Scotia  B3S 1E1
> Tel: 902-450-1700, ext. 298
> Fax: 902-450-1704
> 
> Important:  This e-mail and any files transmitted with it are private and
> confidential and are solely for the use of the addressee.  It may contain
> material which is legally privileged.  If you are not the addressee or the
> person responsible for delivering to the addressee, be advised that you have
> received this e-mail in error and that any use of it is strictly prohibited.
> 
> 
> 
> _______________________________________________
> Help-octave mailing list
> address@hidden
> https://www.cae.wisc.edu/mailman/listinfo/help-octave



reply via email to

[Prev in Thread] Current Thread [Next in Thread]