Author Topic: Ejs Open Source 2 Bar Magnets & Compass Model java applet  (Read 26321 times)

lookang

  • Moderator
  • Hero Member
  • *****
  • Posts: 1772
  • http://weelookang.blogspot.com
    • lookang web
Ejs Open Source 2 Bar Magnets & Compass Model java applet
« on: April 26, 2010, 05:29:18 pm »
Ejs Open Source 2 Bar Magnet & Compass Model java applet
it is an applet based on codes from Wolfgang Christian, Francisco Esquembre, Anne Cox and Fu-Kwun Hwang
http://www.compadre.org/osp/items/detail.cfm?ID=9414
http://www.phy.ntnu.edu.tw/ntnujava/index.php?topic=1582.0

Full screen applet or Problem viewing java?Add http://www.phy.ntnu.edu.tw/ to exception site list
Press the Alt key and the left mouse button to drag the applet off the browser and onto the desktop. This work is licensed under a Creative Commons Attribution 2.5 Taiwan License
  • Please feel free to post your ideas about how to use the simulation for better teaching and learning.
  • Post questions to be asked to help students to think, to explore.
  • Upload worksheets as attached files to share with more users.
Let's work together. We can help more users understand physics conceptually and enjoy the fun of learning physics!
« Last Edit: June 16, 2010, 05:54:44 pm by lookang »

lookang

  • Moderator
  • Hero Member
  • *****
  • Posts: 1772
  • http://weelookang.blogspot.com
    • lookang web
Re: Ejs Open Source 2 Bar Magnet & Compass Model java applet
« Reply #1 on: April 26, 2010, 05:31:12 pm »
trying the make a 2 magnet model.

still debugging

1. working from an earlier model i remixed into http://www.phy.ntnu.edu.tw/ntnujava/index.php?topic=1582.0
2. removed some stuff
3 added the ability to Lon and Ron thanks to Prof Hwang's code http://www.phy.ntnu.edu.tw/ntnujava/index.php?topic=1602.msg6216#msg6216
4 added a scale on the right side of the applet for aid visualization
5 change the number of xField and yField to 41 instead to allow a zoom of 2
6 got the BField to work correctly by adding  Prof Hwang's code http://www.phy.ntnu.edu.tw/ntnujava/index.php?topic=1602.msg6216#msg6216
7 adding the |B| , Bx , By, angle to the display
8 debugging to get it to work beautifully

challenges:
getting getB to work for inside the magnets which i conceptualize to saturate to 225 arbitrarily following the Phet numbers

still the applet will hang when the compass moves on drag.


challenges:
the compass reading, inside magnet, decide whether overlap magnets how?
« Last Edit: June 08, 2010, 10:18:06 am by lookang »

Fu-Kwun Hwang

  • Administrator
  • Hero Member
  • *****
  • Posts: 3062
    • Enjoy the fun of physics with simulations
Re: Ejs Open Source 2 Bar Magnet & Compass Model java applet
« Reply #2 on: May 15, 2010, 12:17:57 am »
I am sorry that I was too busy in the last two weeks so that I was not able to help you with the coding.
Finally, I tried to modify from my previous version and the result (for two magnets) is the following :

Full screen applet or Problem viewing java?Add http://www.phy.ntnu.edu.tw/ to exception site list
Press the Alt key and the left mouse button to drag the applet off the browser and onto the desktop. This work is licensed under a Creative Commons Attribution 2.5 Taiwan License
  • Please feel free to post your ideas about how to use the simulation for better teaching and learning.
  • Post questions to be asked to help students to think, to explore.
  • Upload worksheets as attached files to share with more users.
Let's work together. We can help more users understand physics conceptually and enjoy the fun of learning physics!

lookang

  • Moderator
  • Hero Member
  • *****
  • Posts: 1772
  • http://weelookang.blogspot.com
    • lookang web
Re: Ejs Open Source 2 Bar Magnet & Compass Model java applet
« Reply #3 on: May 15, 2010, 01:59:26 am »
it is beautiful!
thanks! there is so much to learn for this forum. U have made great difference for free access to education.

Thanks a million.

by the way, are you going to AAPT National Meetings Summer 2010, July 17-21 (Portland, OR)?
didn't see your name here http://www.aapt.org/Conferences/sm2010/loader.cfm?csModule=security/getfile&pageid=25158

I have an abstract accepted ;D
WEE Loo Kang Physics Educators as Designers of Simulation Using Easy Java Simulation
Simulated Learning/ Using Simulations to Teach Physics
Contributed FI05 Salon Ballroom II 7/20/2010 2:30 PM 2:40 PM
http://sgeducation.blogspot.com/2010/02/american-association-of-physics.html
« Last Edit: May 16, 2010, 11:03:01 am by lookang »

Fu-Kwun Hwang

  • Administrator
  • Hero Member
  • *****
  • Posts: 3062
    • Enjoy the fun of physics with simulations
Re: Ejs Open Source 2 Bar Magnet & Compass Model java applet
« Reply #4 on: May 15, 2010, 10:38:51 pm »
I will attend GIREP2010 and MPTL join conference this Aug. , but I will not attend the AAPT meeting.


lookang

  • Moderator
  • Hero Member
  • *****
  • Posts: 1772
  • http://weelookang.blogspot.com
    • lookang web
Re: Ejs Open Source 2 Bar Magnet & Compass Model java applet
« Reply #5 on: May 16, 2010, 10:39:47 pm »
all the best!
working on the 2 bar magnet now. it works now!
thanks for
  bf1=getB(x*cs+y*sc,-x*sc+y*cs,xMagnet*cs+yMagnet*sc,-xMagnet*sc+yMagnet*cs);//FKH
  bf2=getB(x*cs2+y*sc2,-x*sc2+y*cs2,xMagnet2*cs2+yMagnet2*sc2,-xMagnet2*sc2+yMagnet2*cs2);//FKH
  //xField[i][j] = b[0];
  //yField[i][j] = b[1];
  xField[i][j] = bf1[0]*cs-bf1[1]*sc+bf2[0]*cs2-bf2[1]*sc2;//FKH
  yField[i][j] = bf1[0]*sc+bf1[1]*cs+bf2[0]*sc2+bf2[1]*cs2;//FKH
//  magField[i][j]=b[2];
  magField[i][j]=Math.sqrt(xField[i][j]*xField[i][j]+yField[i][j]*yField[i][j]);
this the code that made the 2 bar magnet work ;D

Fu-Kwun Hwang

  • Administrator
  • Hero Member
  • *****
  • Posts: 3062
    • Enjoy the fun of physics with simulations
Re: Ejs Open Source 2 Bar Magnet & Compass Model java applet
« Reply #6 on: May 16, 2010, 11:18:25 pm »
It seems that there are someting wrong in your latest code.
Please check it again!

lookang

  • Moderator
  • Hero Member
  • *****
  • Posts: 1772
  • http://weelookang.blogspot.com
    • lookang web
Re: Ejs Open Source 2 Bar Magnet & Compass Model java applet
« Reply #7 on: May 16, 2010, 11:38:16 pm »
is it? i didn't upload the jar yet, only the attachment cos it is still unfinished.
i am still working on it.

but i just reuploaded 02 version on the first post in case you are looking at that one.

i managed to work 2 bar magnets now,

i will try to have no magnet( not working) , one magnet(seems to work) , 2 bar magnet (working ).

i am working on the magnet field only, the compass is not correct yet because i wanted to show the magnet inside as a uniform magnetic field of 225T which the original wolfgang and paco version shows as a large uniform magnetic field due to short distance to any of the dipoles.

will fix the compass after i figure out the field part.
thanks!
« Last Edit: June 08, 2010, 10:19:25 am by lookang »

Fu-Kwun Hwang

  • Administrator
  • Hero Member
  • *****
  • Posts: 3062
    • Enjoy the fun of physics with simulations
Re: Ejs Open Source 2 Bar Magnet & Compass Model java applet
« Reply #8 on: May 17, 2010, 12:31:53 am »
I thought you have found way to modify the code and upload it.
That is fine. Keep up with your work.  ;)

Fu-Kwun Hwang

  • Administrator
  • Hero Member
  • *****
  • Posts: 3062
    • Enjoy the fun of physics with simulations
Re: Ejs Open Source 2 Bar Magnet & Compass Model java applet
« Reply #9 on: May 17, 2010, 11:19:04 pm »
Lookang: I just made some change to the code. Please download latest version.

lookang

  • Moderator
  • Hero Member
  • *****
  • Posts: 1772
  • http://weelookang.blogspot.com
    • lookang web
Re: Ejs Open Source 2 Bar Magnet & Compass Model java applet
« Reply #10 on: May 18, 2010, 10:03:11 pm »
your the man! thanks for the Lon and Ron, will study your technique. hope to be like u one day ;D
« Last Edit: May 18, 2010, 10:10:13 pm by lookang »

Fu-Kwun Hwang

  • Administrator
  • Hero Member
  • *****
  • Posts: 3062
    • Enjoy the fun of physics with simulations
Re: Ejs Open Source 2 Bar Magnet & Compass Model java applet
« Reply #11 on: May 18, 2010, 11:56:31 pm »
The following functions has been modified:
public double[] getB(double xm,double ym) : to compute magnetic field at (xm,ym) related to (xMagnet,yMagnet)

in public void computeField () :
   bf1=getB((x-xMagnet)*cs+(y-yMagnet)*sc,-(x-xMagnet)*sc+(y-yMagnet)*cs);//FKH
   bf2=getB((x-xMagnet2)*cs2+(y-yMagnet2)*sc2,-(x-xMagnet2)*sc2+(y-yMagnet2)*cs2);//FKH
// the above two lines calculate field from two magnets
   xField[ i ][j] = lcst*(bf1[0]*cs-bf1[1]*sc)+rcst*(bf2[0]*cs2-bf2[1]*sc2);//FKH
   yField[ i ][j] = lcst*(bf1[0]*sc+bf1[1]*cs)+rcst*(bf2[0]*sc2+bf2[1]*cs2);//FKH
//calculate the sum of magnet field from two magnets
   magField[ i ][j]=Math.sqrt(xField[ i ][j]*xField[ i ][j]+yField[ i ][j]*yField[ i ][j]);
« Last Edit: June 08, 2010, 10:04:27 am by lookang »

lookang

  • Moderator
  • Hero Member
  • *****
  • Posts: 1772
  • http://weelookang.blogspot.com
    • lookang web
Re: Ejs Open Source 2 Bar Magnet & Compass Model java applet
« Reply #12 on: June 08, 2010, 09:47:17 am »
Hi prof Hwang!
i been thinking and looking at the codes for the 2 bar magnet java applet. I am unable to remix applet faster now, due to my baby girl 3 month old! ;D ;D need to pay more attention to family needs. BTW U can join facebook to see more photos of the baby! LOL http://www.facebook.com/lookang

i managed to get your codes to work in my own remix java applet at the top post.

i am stuck figuring out a clever way to make the getB values to saturate to the direction of the orientation of the bar magnet for both magnets. I have a version 04 that works for one magnet but not both .

This is your code!
public double[] getB(double xm,double ym) {
  double[] b=new double[2];
  for(int i=0; i < nd; i + +) {
   double dx=xm-dipoles[ i ][0];//-xm;////(xMagnet*cs+yMagnet*sc);//FKH
   double dy=ym-dipoles[ i ][1];//-ym;//(-xMagnet*sc+yMagnet*cs);//FKH
   double r2=dx*dx+dy*dy;
   double r=Math.sqrt(r2);
   double r3=r2*r;
   double cos=dx/r;
   double sin=dy/r;
   b[0]+=m*(3*cos*cos-1)/r3; //x component
   b[1]+=m*3*sin*cos/r3; //y component
   if(r2==0) {
   b[0]=b[1]=0;
   }
  }
// b[2] = Math.sqrt(b[0]*b[0]+b[1]*b[1]); // magnitude
// b[3] = Math.atan2(b[1],b[0]); // angle
  return b;
}


This is my code changes (latest version which i still couldn't get it to work the way inside the magnet)
//inside any magnet
if (xCompass<(xm+Magnetsizex/2) && xCompass>(xm-(Magnetsizex/2)) && yCompass<(ym+Magnetsizey/2) && yCompass>(ym-Magnetsizey/2))
{
test = true;
b[0] = (225)*vectorfieldmaxopposite/100; // saturate to direction of magnet Bx'=255 if vectorfieldmaxopposite=1
b[1] = (0)*vectorfieldmaxopposite/100; // saturate to direction of magnet By' =0

}


else // original code for field
   {
   test=false;
   b[0]+=m*(3*cos*cos-1)/r3*vectorfieldmaxopposite/100; ; //x component vectorfieldmaxopposite/100 is a factor i made
  b[1]+=m*3*sin*cos/r3*vectorfieldmaxopposite/100; ; //y component
}



it is not working the way that i conceptualize it would work.
chance to look at it and make the codes work?
i think your teaching method is great, u do it on your applet and i study it. can help? ;D
« Last Edit: June 08, 2010, 10:13:52 am by lookang »

Fu-Kwun Hwang

  • Administrator
  • Hero Member
  • *****
  • Posts: 3062
    • Enjoy the fun of physics with simulations
Re: Ejs Open Source 2 Bar Magnet & Compass Model java applet
« Reply #13 on: June 08, 2010, 04:53:31 pm »
Are you trying to add a visual effect to the applet, or you really need a very accurate calculation for the magnetic field insode the magnet?

The magnetic field of the above applet were calculated with finite number of current loop.
The magnetic field strength is inverse proportional to distance squrare.
So the error dur to field calculation become too large. May be that is the reason you try to "saturate: it.

I would suggest you just calculate the field at one of the end point as the magnetic field inside the magnet. i.e. assume the field is uniform inside the magnet (the same vector as the field at the center of end point).

lookang

  • Moderator
  • Hero Member
  • *****
  • Posts: 1772
  • http://weelookang.blogspot.com
    • lookang web
Re: Ejs Open Source 2 Bar Magnet & Compass Model java applet
« Reply #14 on: June 08, 2010, 08:46:38 pm »
Are you trying to add a visual effect to the applet, or you really need a very accurate calculation for the magnetic field inside the magnet?
the visual effect of a uniform B field, not accurate calculation.



The magnetic field of the above applet were calculated with finite number of current loop.
The magnetic field strength is inverse proportional to distance square.
So the error dur to field calculation become too large. May be that is the reason you try to "saturate: it.
Yes! i don't believe B field inside the bar magnet can be so big and direction random, it should an uniform B field in my understanding.


I would suggest you just calculate the field at one of the end point as the magnetic field inside the magnet. i.e. assume the field is uniform inside the magnet (the same vector as the field at the center of end point).
i don't quite get what is mentioned here.
but i will try again soon :)
« Last Edit: June 08, 2010, 10:09:17 pm by lookang »