Tuesday, October 13, 2015

lecture october 13

Remember to enter strings in single quotes
Enter a planet name in single quotes:Enter the mass in multiples of earth's mass: 'mercury'
Enter the length of the planetary year in Earth years: 0.055
Enter the mean orbital velocity in km/sec: 0.24

ans =

        name: []
        mass: 'mercury'
        year: 0.0550
    velocity: 0.2400

Remember to enter strings in single quotes
Enter a planet name in single quotes:'mercury'
Enter the mass in multiples of earth's mass: 0.055
Enter the length of the planetary year in Earth years: 0.24
Enter the mean orbital velocity in km/sec: 47.89

ans =

        name: 'mercury'
        mass: 0.0550
        year: 0.2400
    velocity: 47.8900

Remember to enter strings in single quotes
Enter a planet name in single quotes:'venus'
Enter the mass in multiples of earth's mass: 0.815
Enter the length of the planetary year in Earth years: 0.62
Enter the mean orbital velocity in km/sec: 35.02

ans =

        name: 'venus'
        mass: 0.8150
        year: 0.6200
    velocity: 35.0200

Remember to enter strings in single quotes
Enter a planet name in single quotes:'earth'
Enter the mass in multiples of earth's mass: 1
Enter the length of the planetary year in Earth years: 1
Enter the mean orbital velocity in km/sec: 29.79

ans =

        name: 'earth'
        mass: 1
        year: 1
    velocity: 29.7900

Remember to enter strings in single quotes
Enter a planet name in single quotes:'mars'
Enter the mass in multiples of earth's mass: 0.107
Enter the length of the planetary year in Earth years: 1.88
Enter the mean orbital velocity in km/sec: 24.12

ans =

        name: 'mars'
        mass: 0.1070
        year: 1.8800
    velocity: 24.1200

Remember to enter strings in single quotes
Enter a planet name in single quotes:'jupiter'
Enter the mass in multiples of earth's mass: 318
Enter the length of the planetary year in Earth years: 11.86
Enter the mean orbital velocity in km/sec: 13.06

ans =

        name: 'jupiter'
        mass: 318
        year: 11.8600
    velocity: 13.0600

Remember to enter strings in single quotes
Enter a planet name in single quotes:'saturn'
Enter the mass in multiples of earth's mass: 95
Enter the length of the planetary year in Earth years: 29.46
Enter the mean orbital velocity in km/sec: 9.64

ans =

        name: 'saturn'
        mass: 95
        year: 29.4600
    velocity: 9.6400

Remember to enter strings in single quotes
Enter a planet name in single quotes:'uranus'
Enter the mass in multiples of earth's mass: 15
Enter the length of the planetary year in Earth years: 84.01
Enter the mean orbital velocity in km/sec: 6.81

ans =

        name: 'uranus'
        mass: 15
        year: 84.0100
    velocity: 6.8100

Remember to enter strings in single quotes
Enter a planet name in single quotes:'neptune'
Enter the mass in multiples of earth's mass: 17
Enter the length of the planetary year in Earth years: 164.8
Enter the mean orbital velocity in km/sec: 5.43

ans =

        name: 'neptune'
        mass: 17
        year: 164.8000
    velocity: 5.4300

Remember to enter strings in single quotes
Enter a planet name in single quotes:'pluto'
Enter the mass in multiples of earth's mass: 000.002
Enter the length of the planetary year in Earth years: 247.7
Enter the mean orbital velocity in km/sec: 4.74

ans =

        name: 'pluto'
        mass: 0.0020
        year: 247.7000
    velocity: 4.7400


planetary =

1x9 struct array with fields:

    name
    mass
    year
    velocity

>> planetary.name

ans =

mercury


ans =

venus


ans =

earth


ans =

mars


ans =

jupiter


ans =

saturn


ans =

uranus


ans =

neptune


ans =

pluto

>> nameas=[planetary.name];
>> nameas=char(planetary.name);
>> struct2table(planetary)

ans =

      name       mass     year     velocity
    _________    _____    _____    ________

    'mercury'    0.055     0.24    47.89  
    'venus'      0.815     0.62    35.02  
    'earth'          1        1    29.79  
    'mars'       0.107     1.88    24.12  
    'jupiter'      318    11.86    13.06  
    'saturn'        95    29.46     9.64  
    'uranus'        15    84.01     6.81  
    'neptune'       17    164.8     5.43  
    'pluto'      0.002    247.7     4.74  

>> mean(planetary.velocity)
Error using mean
Too many input arguments.

this is the code that goes with the planetary homework/lecture question with everything but the average speed working. So it was basically just getting a better handle on structures which is kewl.

For some part of the class the notes were on symbolic functions which, using the schools mandated matlab program, was not available to me so... anyway this stuff is pretty nifty, like having a variable equal to another variable that is a symbol makes the initial variable a symbolic matrix. one can also define the symbols that are used in a equation and then run that equation. Basically the computer does all the work and the user just has to remember to format correctly.
avoid these symbol names:
D,E,I,O,beta,zeta,theta,psi,gamma,Ci,Si,Ei
they are already used as either functions or specific variables in matlab and you would have to clear the work space to get that variable back. might be great to not clear the workspace for today.


Apparently the values of symbols in the equations are just there for visual effect and a function is required to replace certain symbols with their values given by the user. At this point in time everyone else is doing examples and writing exercises and equations based off of symbols: x,a,b,c,d that were created at the beginning. ten of each exercise and equation, but we can just copy and paste so it doesnt  take much time at all.

the numden function is pretty great, it gives a numerator and denomonator for what symbol you want to know though the function does not work in the way that was intended to simplify but only if it simplifies to easily. Had the equation been difficult to simplify the desired results appears. You may also use different mathmatic operation systems for num den, there is also an expand and factor func for these two. collect function should work for all, despite equations or expressions. actually collect requires an expression.

next subject is MuPAD, it's like having a maple window in matlab though your computer might not run it if maple is already on your hardrive.

much as the name would suggest, the simplify function simplifies the equation

you can make a vector in to a poly equation and from there make it a sym using poly2sym and sym2poly functions, keep an eye on workspace to see if there is anything weird in the size.

so to solve for the function you would use a combination of the solve and/or the sub functions. solve sets it to solve the equation equal to zero unless a second element is added. if the variables are defined as symbols then " ' " are not necessary. MuPAD only recognizes ints and floating points, accurate with floating point up to 32 places. if you solve for a specific symbol place the variable in single quotations. When you solve a system of equations using solve the answers are put into a structure. By inputting answer.variable the answer will print.
this is an upside down hand example that we would input in matlab to solve for a specific variable from an equation.

When working with a nonlinear system, well you dont  work with nonlinear equations. Who are you trying to impress? We are not mapping theoretical physics for the fifth dimension. All engineering can be based off models of linear equations.
To use the subs function, the equation is called first then the object that is wished to be subbed, finally the new value in place of the subbed value.

No comments:

Post a Comment