NTNUJAVA Virtual Physics Laboratory
Enjoy the fun of physics with simulations!
Backup site http://enjoy.phy.ntnu.edu.tw/ntnujava/
October 23, 2017, 08:41:05 pm *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
 
   Home   Help Search Login Register  
Never underestimate others. Never overestimate oneself. ...Wisdom
Google Bookmarks Yahoo My Web MSN Live Netscape Del.icio.us FURL Stumble Upon Delirious Ask FaceBook

Pages: [1]   Go Down
  Print  
Author Topic: Ejs Open Source 2 Bar Magnets & Compass Model java applet  (Read 19561 times)
0 Members and 1 Guest are viewing this topic. Click to toggle author information(expand message area).
lookang
Moderator
Hero Member
*****
Offline Offline

Posts: 1784


http://weelookang.blogspot.com


WWW
«
Embed this message
on: April 26, 2010, 04:29:18 pm » posted from:SINGAPORE,SINGAPORE,SINGAPORE

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

Embed a running copy of this simulation

Embed a running copy link(show simulation in a popuped window)
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!


* Ejs Open Source 2 Bar Magnets & Compass Model java applet.png (94.95 KB, 799x591 - viewed 1484 times.)
« Last Edit: June 16, 2010, 04:54:44 pm by lookang » Logged
lookang
Moderator
Hero Member
*****
Offline Offline

Posts: 1784


http://weelookang.blogspot.com


WWW
«
Embed this message
Reply #1 on: April 26, 2010, 04:31:12 pm » posted from:SINGAPORE,SINGAPORE,SINGAPORE

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?


*** There are 5 more attached files. You need to login to acces it!
« Last Edit: June 08, 2010, 09:18:06 am by lookang » Logged
Fu-Kwun Hwang
Administrator
Hero Member
*****
Offline Offline

Posts: 3080



WWW
«
Embed this message
Reply #2 on: May 14, 2010, 11:17:57 pm » posted from:Taipei,T\'ai-pei,Taiwan

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 :

Embed a running copy of this simulation

Embed a running copy link(show simulation in a popuped window)
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!
Logged
lookang
Moderator
Hero Member
*****
Offline Offline

Posts: 1784


http://weelookang.blogspot.com


WWW
«
Embed this message
Reply #3 on: May 15, 2010, 12: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 Grin
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, 10:03:01 am by lookang » Logged
Fu-Kwun Hwang
Administrator
Hero Member
*****
Offline Offline

Posts: 3080



WWW
«
Embed this message
Reply #4 on: May 15, 2010, 09:38:51 pm » posted from:Taipei,T'ai-pei,Taiwan

I will attend GIREP2010 and MPTL join conference this Aug. , but I will not attend the AAPT meeting.

Logged
lookang
Moderator
Hero Member
*****
Offline Offline

Posts: 1784


http://weelookang.blogspot.com


WWW
«
Embed this message
Reply #5 on: May 16, 2010, 09:39:47 pm » posted from:Singapore,,Singapore

all the best!
working on the 2 bar magnet now. it works now!
thanks for
Code:
  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 Grin


*** There are 1 more attached files. You need to login to acces it!
Logged
Fu-Kwun Hwang
Administrator
Hero Member
*****
Offline Offline

Posts: 3080



WWW
«
Embed this message
Reply #6 on: May 16, 2010, 10:18:25 pm » posted from:Taipei,T\'ai-pei,Taiwan

It seems that there are someting wrong in your latest code.
Please check it again!
Logged
lookang
Moderator
Hero Member
*****
Offline Offline

Posts: 1784


http://weelookang.blogspot.com


WWW
«
Embed this message
Reply #7 on: May 16, 2010, 10:38:16 pm » posted from:Singapore,,Singapore

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, 09:19:25 am by lookang » Logged
Fu-Kwun Hwang
Administrator
Hero Member
*****
Offline Offline

Posts: 3080



WWW
«
Embed this message
Reply #8 on: May 16, 2010, 11:31:53 pm » posted from:Taipei,T\'ai-pei,Taiwan

I thought you have found way to modify the code and upload it.
That is fine. Keep up with your work.  Wink
Logged
Fu-Kwun Hwang
Administrator
Hero Member
*****
Offline Offline

Posts: 3080



WWW
«
Embed this message
Reply #9 on: May 17, 2010, 10:19:04 pm » posted from:Taipei,T\'ai-pei,Taiwan

Lookang: I just made some change to the code. Please download latest version.
Logged
lookang
Moderator
Hero Member
*****
Offline Offline

Posts: 1784


http://weelookang.blogspot.com


WWW
«
Embed this message
Reply #10 on: May 18, 2010, 09:03:11 pm » posted from:Singapore,,Singapore

your the man! thanks for the Lon and Ron, will study your technique. hope to be like u one day Grin
« Last Edit: May 18, 2010, 09:10:13 pm by lookang » Logged
Fu-Kwun Hwang
Administrator
Hero Member
*****
Offline Offline

Posts: 3080



WWW
«
Embed this message
Reply #11 on: May 18, 2010, 10:56:31 pm » posted from:Taipei,T\'ai-pei,Taiwan

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, 09:04:27 am by lookang » Logged
lookang
Moderator
Hero Member
*****
Offline Offline

Posts: 1784


http://weelookang.blogspot.com


WWW
«
Embed this message
Reply #12 on: June 08, 2010, 08:47:17 am » posted from:Singapore,,Singapore

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! Grin Grin 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? Grin


* Screen shot 2010-06-08 at AM 10.00.36.png (32.72 KB, 238x268 - viewed 407 times.)

* Screen shot 2010-06-08 at AM 10.00.50.png (55.25 KB, 465x276 - viewed 413 times.)
« Last Edit: June 08, 2010, 09:13:52 am by lookang » Logged
Fu-Kwun Hwang
Administrator
Hero Member
*****
Offline Offline

Posts: 3080



WWW
«
Embed this message
Reply #13 on: June 08, 2010, 03:53:31 pm » posted from:Taipei,T\'ai-pei,Taiwan

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).
Logged
lookang
Moderator
Hero Member
*****
Offline Offline

Posts: 1784


http://weelookang.blogspot.com


WWW
«
Embed this message
Reply #14 on: June 08, 2010, 07:46:38 pm » posted from:Singapore,,Singapore

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 Smiley
« Last Edit: June 08, 2010, 09:09:17 pm by lookang » Logged
lookang
Moderator
Hero Member
*****
Offline Offline

Posts: 1784


http://weelookang.blogspot.com


WWW
«
Embed this message
Reply #15 on: June 08, 2010, 09:56:18 pm » posted from:Singapore,,Singapore

i did it!!! with your guidance for the past 3 years+, i managed to do this just now! LOL Grin Grin

// inside both magnet1&2
if ((xCompass<(xMagnet+Magnetsizex/2) && xCompass>(xMagnet-(Magnetsizex/2)) && yCompass<(yMagnet+Magnetsizey/2) && yCompass>(yMagnet-Magnetsizey/2))&&(xCompass<(xMagnet2+Magnetsizex2/2) && xCompass>(xMagnet2-(Magnetsizex2/2)) && yCompass<(yMagnet2+Magnetsizey2/2) && yCompass>(yMagnet2-Magnetsizey2/2)))
{
//test = true;
// create uniform field
bxField = (lcst*(225*cs-0*sc)+rcst*(225*cs2-0*sc2))*vectorfieldmaxopposite/100; // saturate to direction of magnet Bx'=0 for both magnets
byField = (lcst*(225*sc+0*cs)+rcst*(225*sc2+0*cs2))*vectorfieldmaxopposite/100;//saturate to direction of magnet By' =0 for both magnets

}
//inside magnet1
else if (xCompass<(xMagnet+Magnetsizex/2) && xCompass>(xMagnet-(Magnetsizex/2)) && yCompass<(yMagnet+Magnetsizey/2) && yCompass>(yMagnet-Magnetsizey/2))
{
//test = false;
bxField = (lcst*(225*cs-0*sc)+rcst*(bf2[0]*cs2-bf2[1]*sc2))*vectorfieldmaxopposite/100;// uniform B1x=225 but B2x still calculate normally
byField = (lcst*(225*sc+0*cs)+rcst*(bf2[0]*sc2+bf2[1]*cs2))*vectorfieldmaxopposite/100;//uniform B1y=0 but B2y still calculate normally
}

// inside magnet2
else if (xCompass<(xMagnet2+Magnetsizex2/2) && xCompass>(xMagnet2-(Magnetsizex2/2)) && yCompass<(yMagnet2+Magnetsizey2/2) && yCompass>(yMagnet2-Magnetsizey2/2))
{
//test = false;
bxField = (lcst*(bf1[0]*cs-bf1[1]*sc)+rcst*(225*cs2-0*sc2))*vectorfieldmaxopposite/100;// calculate normally B1x but B2x = 225 uniform
byField = (lcst*(bf1[0]*sc+bf1[1]*cs)+rcst*(225*sc2+0*cs2))*vectorfieldmaxopposite/100;//calculate normally B1y but B2y = 0 uniform
}

else
{
// test=false;
bxField = lcst*(bf1[0]*cs-bf1[1]*sc)+rcst*(bf2[0]*cs2-bf2[1]*sc2);//FKH
byField = lcst*(bf1[0]*sc+bf1[1]*cs)+rcst*(bf2[0]*sc2+bf2[1]*cs2);//FKH
}

Thanks again Prof Hwang! your forum rocks!


*** There are 1 more attached files. You need to login to acces it!
« Last Edit: June 08, 2010, 10:02:47 pm by lookang » Logged
Fu-Kwun Hwang
Administrator
Hero Member
*****
Offline Offline

Posts: 3080



WWW
«
Embed this message
Reply #16 on: June 08, 2010, 11:32:44 pm » posted from:Taipei,T\'ai-pei,Taiwan

It is great that you find out the way to solve it.  Cheesy
Logged
Pages: [1]   Go Up
  Print  
Never underestimate others. Never overestimate oneself. ...Wisdom
 
Jump to:  


Related Topics
Subject Started by Replies Views Last post
Ejs Open Source Magnet and Soleniod Magnetic Induction Model Java Applet
Collaborative Community of EJS
lookang 1 6314 Last post November 25, 2009, 11:19:27 pm
by lookang
Ejs Open Source Ideal Transformer Model Java Applet
Collaborative Community of EJS
lookang 1 8285 Last post December 17, 2009, 02:55:54 pm
by Coffee makers
Ejs Open Source High Voltage Transmission Model Java Applet
Collaborative Community of EJS
lookang 3 7682 Last post December 17, 2009, 02:56:08 pm
by Coffee makers
Ejs Open Source Ideal Gas Model with Maxwell Distribution of Speed Java Applet
Collaborative Community of EJS
lookang 2 7542 Last post April 26, 2010, 08:31:24 pm
by ahmedelshfie
Ejs Open Source Bar Magnet Model java applet
Simulations from other web sites
ahmedelshfie 2 7670 Last post April 26, 2010, 07:48:35 pm
by ahmedelshfie
Powered by MySQL Powered by PHP Powered by SMF 1.1.13 | SMF © 2006-2011, Simple Machines LLC Valid XHTML 1.0! Valid CSS!
Page created in 0.094 seconds with 24 queries.since 2011/06/15