T-Mobile 9:46 AM bblearn.nau.edu EE 364 Lab 7 Magnetic Fields Lab Overview This
ID: 3599573 • Letter: T
Question
T-Mobile 9:46 AM bblearn.nau.edu EE 364 Lab 7 Magnetic Fields Lab Overview This lab is designed to enhance the understanding of static magnetic fields due to current flow within a line. This exercise will consist of coding within MATLAB to visual field lines. The goal is to consider a line containing charged particles and the magnetic dipole. Rules of Engagement No more than 2 people in a group. Open books and open Internet. Each group is expected to spend 2-3 hours total on this exercise. All code should be organized into a single MATLAB file. (due by next lab) .Put names and CUPT IDs of the lab members into the file header Materials: Computer with Matlab . Steps: 1. Discuss matlab template examples. 2. Magnetic field from Biot-Savart law 3. Students write code in matlab to plot the magnetic fields a. Plot the 3D magnetic field current lowing along z-axis i. Grid from -10 to 10 on the x, y, and z-axes in increments of i ii Atz-0 (no current), z0I is in +z, z0 I is in-z. b. Plot the 3D magnetic field lines of dipole centered at origin i. Loop is in the x-y plane. ii. Radius of loop is 5 iii. Current can flow either direction. iv. Use differential angle of d: 10 loop from /10 to 2 around the loop. v. dl =-a sin + a cos + 02 (current is counterclockwise) vi put loop into (x.y.z) coordinates, find R unit vector, find cross product. vii. Hint i =-cos9) j = ( . k = (x-a sin ) R R=i+j+k Grading (100pts): Subt single matabExplanation / Answer
package com;
import java.util.ArrayList;
public class ArrayWithExponentAsIndexPolynomial implements PolynomialInterface
{
int polynomial[];
int highExp;
ArrayWithExponentAsIndexPolynomial()
{
polynomial=new int[200];
}
ArrayWithExponentAsIndexPolynomial(String pol)
{
polynomial=new int[200];
highExp=0;
int co=0;//Coefficient
int exp=0;//exponent
//Convert the polynomial string into linked list of polynomial terms
for(int i=0;i<pol.length();i++)
{
co=0;
exp=0;
//Find coefficient
while(pol.charAt(i)!='x' && pol.charAt(i)!='X' )
{
if(pol.charAt(i)=='-')
{
i++;
while(i<pol.length())
{
if(pol.charAt(i)!='x' && pol.charAt(i)!='X' )
{
String sub=pol.substring(i,i+1);
co=co*10+Integer.parseInt(sub);
}
else
break;
i++;
}
co=co*-1;
}
else if (pol.charAt(i)=='+')
{
i++;
}
else
{
String sub=pol.substring(i,i+1);
co=co*10+Integer.parseInt(sub);
i++;
}
if(i>=pol.length())
break;
}
i++;//skip x
if(i==pol.length())
{
if(pol.charAt(i-1)=='x' || pol.charAt(i-1)=='X')
exp=1;
}
i++;//skip ^
if(i<pol.length())
while(pol.charAt(i)!='-' && pol.charAt(i)!='+' )
{
String sub=pol.substring(i,i+1);
exp=exp*10+Integer.parseInt(sub);
i++;
if(i>=pol.length())
break;
}
if(highExp<exp)
highExp=exp;
addATerm(exp,co);
i--;
}
}
// stores the coefficient at index(exp)
void addATerm(int exp,int co)
{
// store the coefficient at index(exp)
polynomial[exp]=co;
}
int getHigh()
{
return highExp;
}
@Override
//Adds two polynomials and returns the resultant polynomial
public PolynomialInterface add(PolynomialInterface other)
{
int high;
ArrayWithExponentAsIndexPolynomial temp=new ArrayWithExponentAsIndexPolynomial();
ArrayWithExponentAsIndexPolynomial otherPoly=(ArrayWithExponentAsIndexPolynomial)other;
if(this.getHigh()<otherPoly.getHigh())
{
high=otherPoly.getHigh();
temp.highExp=otherPoly.getHigh();
}
else
{
high=this.getHigh();
temp.highExp=this.getHigh();
}
for(int i=0;i<=high;i++)
{
if(this.polynomial[i]!=0 && otherPoly.polynomial[i]!=0)
{
temp.polynomial[i]=this.polynomial[i]+otherPoly.polynomial[i];
}
else if (this.polynomial[i]==0 && otherPoly.polynomial[i]!=0)
{
temp.polynomial[i]=otherPoly.polynomial[i];
}
else if (this.polynomial[i]!=0 && otherPoly.polynomial[i]==0)
{
temp.polynomial[i]=this.polynomial[i];
}
}
return temp;
}
@Override
//Substracts one polynomial from another and returns the resultant polynomial
public PolynomialInterface subtract(PolynomialInterface other)
{
int high;
ArrayWithExponentAsIndexPolynomial temp=new ArrayWithExponentAsIndexPolynomial();
ArrayWithExponentAsIndexPolynomial otherPoly=(ArrayWithExponentAsIndexPolynomial)other;
if(this.getHigh()<otherPoly.getHigh())
{
high=otherPoly.getHigh();
temp.highExp=otherPoly.getHigh();
}
else
{
high=this.getHigh();
temp.highExp=this.getHigh();
}
for(int i=0;i<=high;i++)
{
if(this.polynomial[i]!=0 && otherPoly.polynomial[i]!=0)
{
temp.polynomial[i]=this.polynomial[i]-otherPoly.polynomial[i];
}
else if (this.polynomial[i]==0 && otherPoly.polynomial[i]!=0)
{
temp.polynomial[i]=0-otherPoly.polynomial[i];
}
else if (this.polynomial[i]!=0 && otherPoly.polynomial[i]==0)
{
temp.polynomial[i]=this.polynomial[i];
}
}
return temp;
}
public String toString()
{
String poly="";
//Convert the linked list into polynomial string
for(int i=this.getHigh();i>=0;i--)
{
if(polynomial[i]!=0)
{
if(i==1)
{
if(polynomial[i]<0)
poly=poly+"-"+polynomial[i]*-1+"x";
else
poly=poly+polynomial[i]+"x";
}
else if(i!=0)
{
if(polynomial[i]<0)
poly=poly+"-"+polynomial[i]*-1+"x^"+i;
else
{
if(i!=this.getHigh())
poly=poly+"+"+polynomial[i]+"x^"+i;
else
poly=poly+polynomial[i]+"x^"+i;
}
}
else
{
if(polynomial[i]<0)
poly=poly+"-"+polynomial[i]*-1;
else
poly=poly+"+"+polynomial[i];
}
}
}
return poly;
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.