NeuseRvrRat hello Mr. NSA! 35376 Posts user info edit post |
is there a way to plot a function in excel other than just calculating a bunch of points along the function and sticking in a trend line or something?
/noob 10/18/2008 4:13:32 PM |
NeuseRvrRat hello Mr. NSA! 35376 Posts user info edit post |
nevermind, i gave up on that so i'm trying to learn matlab
in a unity lab, how do i change matlab's current directory to one where i can save stuff (ie. somewhere on the K: drive)? 10/18/2008 5:02:30 PM |
The Dude All American 6502 Posts user info edit post |
post the function so I know what you are working with 10/18/2008 5:12:52 PM |
moron All American 34142 Posts user info edit post |
If all you need to do is plot a function, there are easier ways than matlab. 10/18/2008 5:17:12 PM |
NeuseRvrRat hello Mr. NSA! 35376 Posts user info edit post |
ok, i kinda got this figured out. this is my first time using matlab unfortunately.
here's my code:
w=0:.0001:200; k=4090000 c=22800 m=2000 h=k*((k^2+(c*w)^2)^0.5)/(((k-m*w^2)^2+(c*w)^2)^0.5) plot(w,h) title('Frequency Response Magnification Factor') xlabel('Frequency (rad/s)') ylabel('Magnification Factor') grid on
i get this error:
>> run E:\magfac
k =
4090000
c =
22800
m =
2000
??? Error using ==> mpower Matrix must be square.
Error in ==> magfac at 5 h=k*((k^2+(c*w)^2)^0.5)/(((k-m*w^2)^2+(c*w)^2)^0.5)
Error in ==> run at 57 evalin('caller', [s ';']); 10/18/2008 5:24:09 PM |
NeuseRvrRat hello Mr. NSA! 35376 Posts user info edit post |
this code worked fine for the other function:
t=0:.0001:.5; Y=0.1 k=4090000 c=22800 m=2000 w=101.81 p=atan((m*c*w^3)/(k*(k-m*w^2)+(c*w)^2)) x=(Y*(k^2+(c*w)^2)^0.5)/((k-m*w^2)^2+(c*w)^2)^0.5*cos(w*t-p) plot(t,x) title('Steady State Motion of Landing Gear') xlabel('Time (s)') ylabel('Vertical Displacement (m)') grid on
[Edited on October 18, 2008 at 5:34 PM. Reason : ^^i need to learn matlab anyway] 10/18/2008 5:26:40 PM |
moron All American 34142 Posts user info edit post |
link
[Edited on October 18, 2008 at 5:58 PM. Reason : ] 10/18/2008 5:34:37 PM |
NeuseRvrRat hello Mr. NSA! 35376 Posts user info edit post |
i'd rather just find out why the matlab code isn't working
[Edited on October 18, 2008 at 5:42 PM. Reason : i appreciate your help though] 10/18/2008 5:41:39 PM |
moron All American 34142 Posts user info edit post |
I googled the error, and it seems you need to use .^
Quote : | "Technically, you only need dots in front of ^ operators for which the first argument might be a vector, and * and / operators for which the quantities on each side of the operator could both be vectors. The MATLAB function quad gives a vector argument to the function it is integrating, so vectors may crop up when you don't expect them. The safest thing is to put a dot in front of every * /, and ^ operator in all your functions. If you forget the dots in front of operators you may get hard-to-understand error messages. If somewhere you have written a^b instead of a.^b, you may get ??? Error using ==> mpower Matrix must be square. " |
- http://www.physics.wustl.edu/~alford/p217/matlab_hints.html
.^ just tells matlab, IIRC, to process corresponding values together regardless of if the set of those values lines up.
like if you have a set of values a=[1,2,3,4] and b=[1,2,3,4,5,6] and use just did a^b it'd throw an error because they don't match. a.^b would just do the first 4 because that's all it has data for.
note: this info is based on very vague recollection of working with matlab
[Edited on October 18, 2008 at 5:51 PM. Reason : obama '08]10/18/2008 5:45:09 PM |
NeuseRvrRat hello Mr. NSA! 35376 Posts user info edit post |
yeah, i found the .^ thing too, but it still wasn't working. lemme try again. 10/18/2008 5:49:13 PM |
moron All American 34142 Posts user info edit post |
If you want, you can try your original code with w=0:.5:200 you don't need a .00001 resolution from 0 to 200, that's a LOT of values. 10/18/2008 5:50:40 PM |
NeuseRvrRat hello Mr. NSA! 35376 Posts user info edit post |
i didn't even know what the .0001 stood for. someone told me to go with that. 10/18/2008 5:54:49 PM |
NeuseRvrRat hello Mr. NSA! 35376 Posts user info edit post |
all i need to do is graph h as a function of w based on the function in line 5
code:
w=0:.5:200; k=4090000 c=22800 m=2000 h=(k*((k^2+(c*w).^2).^0.5)/(((k-m*w.^2).^2+(c*w).^2).^0.5)) plot(w,h) title('Frequency Response Magnification Factor') xlabel('Frequency (rad/s)') ylabel('Magnification Factor') grid on
output a graph with constant h and gave me this in the command window:
>> run E:\magfac
k =
4090000
c =
22800
m =
2000
h =
4.8747e+005
that value for h is the value it had on the graph 10/18/2008 5:58:20 PM |
Wickerman All American 2404 Posts user info edit post |
Matlab rocks.. I get paid to write matlab code 10/18/2008 5:59:24 PM |
NeuseRvrRat hello Mr. NSA! 35376 Posts user info edit post |
^can you help me out? i'd be most grateful.
[Edited on October 18, 2008 at 6:00 PM. Reason : it doesn't seem difficult, this is just my first time ever even seeing it] 10/18/2008 6:00:22 PM |
moron All American 34142 Posts user info edit post |
hmm... maybe try this as your h, i noticed you left out some .^ and you want to put them in front of the multiplies too
h=(k.*((k.^2+(c.*w).^2).^0.5)/(((k-m.*w.^2).^2+(c.*w).^2).^0.5)) 10/18/2008 6:01:25 PM |
NeuseRvrRat hello Mr. NSA! 35376 Posts user info edit post |
i didn't think i should do it for k since it's a constant, not a matrix 10/18/2008 6:03:12 PM |
moron All American 34142 Posts user info edit post |
i'm just guessing... your exponents are constants too and it throws an error. It looks like you're trying to use the .5^2 to replace absolute value, maybe you should see what matlab's absolute value function is? 10/18/2008 6:04:49 PM |
NeuseRvrRat hello Mr. NSA! 35376 Posts user info edit post |
good point. i'm actually supposed to plot the abs. value of that h value anyway
i'll give it a try 10/18/2008 6:07:46 PM |
NeuseRvrRat hello Mr. NSA! 35376 Posts user info edit post |
this returns the same constant value stuff:
w=0:.5:200; k=4090000 c=22800 m=2000 h=abs(k*(sqrt(k^2+(c*w).^2))/sqrt((k-m*w.^2).^2+(c*w).^2)) plot(w,h) title('Frequency Response Magnification Factor') xlabel('Frequency (rad/s)') ylabel('Magnification Factor') grid on
as does this:
w=0:.5:200; k=4090000 c=22800 m=2000 h=abs(k.*(sqrt(k.^2+(c.*w).^2))/sqrt((k-m.*w.^2).^2+(c.*w).^2)) plot(w,h) title('Frequency Response Magnification Factor') xlabel('Frequency (rad/s)') ylabel('Magnification Factor') grid on
[Edited on October 18, 2008 at 6:13 PM. Reason : .....] 10/18/2008 6:12:01 PM |
NeuseRvrRat hello Mr. NSA! 35376 Posts user info edit post |
i'll buy a cookout tray tonight for whoever gets this thing working for me and explains it to me 10/18/2008 6:14:17 PM |
NeuseRvrRat hello Mr. NSA! 35376 Posts user info edit post |
hell, i tried this and get that same damn graph:
w=0:.5:200; k=4090000 c=22800 m=2000 h=abs(k.*(sqrt(k.^2.+(c.*w).^2))/sqrt((k-m.*w.^2).^2.+(c.*w).^2)) plot(w,h) title('Frequency Response Magnification Factor') xlabel('Frequency (rad/s)') ylabel('Magnification Factor') grid on 10/18/2008 6:23:28 PM |
NeuseRvrRat hello Mr. NSA! 35376 Posts user info edit post |
ok, i've done some googling and it's because it's getting two values when it takes the sqrt. i can find out how to make it take only the positive value. if i do abs(sqrt(x)) i think it's still getting two values, they're just the same (ie. two positive values)
[Edited on October 18, 2008 at 6:32 PM. Reason : quintuple post y'all] 10/18/2008 6:31:41 PM |
darkone (\/) (;,,,;) (\/) 11610 Posts user info edit post |
You do realize that you're doing in MATLAB what you didn't want to do in Excel, right? 10/18/2008 6:38:08 PM |
NeuseRvrRat hello Mr. NSA! 35376 Posts user info edit post |
google didn't tell me how to do it in excel. i had some code to go off of for matlab, so i figured i'd give it a shot.
they ought to replace that godforsaken fortran requirement with a matlab class so i wouldn't be SOL right now.
[Edited on October 18, 2008 at 6:40 PM. Reason : and the one i got to work was simpler than it would've been in excel] 10/18/2008 6:40:08 PM |
moron All American 34142 Posts user info edit post |
you're going to slap yourself when you hear the problem...
you also have to put a period in front of the division symbol too 10/18/2008 6:42:31 PM |
NeuseRvrRat hello Mr. NSA! 35376 Posts user info edit post |
when would you like your cookout tray? 10/18/2008 6:44:13 PM |
moron All American 34142 Posts user info edit post |
i'll PM you some time next week
Also, you realize that if you have a Mac or get Xwin32 for Windows you can do matlab from the comfort of your home, by remotely logging in to the linux cluster and running matlab from there? 10/18/2008 6:48:34 PM |
NeuseRvrRat hello Mr. NSA! 35376 Posts user info edit post |
yes, but my home internet is too slow for the remote stuff
it's free. you get what you pay for.
supposedly it's included in our rent, but i wish they'd lower the rent and make us just get roadrunner or something
[Edited on October 18, 2008 at 6:50 PM. Reason : it's wireless only] 10/18/2008 6:50:08 PM |
NeuseRvrRat hello Mr. NSA! 35376 Posts user info edit post |
i got another question. i'm using "atan" to find an angle as a function of frequency. i want it to graph the positive angle that results in that tangent value. here's the code:
w=0:.5:200; k=4090000 c=22800 m=2000 p=atan((m.*c.*w.^3)./(k*(k-m.*w.^2)+(c.*w).^2)) plot(w,p) title('Frequency Response Phase Angle') xlabel('Frequency (rad/s)') ylabel('Phase Angle (rad)') grid on
i get a graph with a vertical asymptote where the value of "p" goes negative. pretty much what i want is all the values to the right of that point to have 180 degrees or pi added to them so i get a nice continuous curve. absolute value doesn't help because then it just gives the positive of the angle 180 degrees from the angle i really want. i know this is very unclear, but any ideas?
edit: in other words, "atan" gives a value between -pi/2 and pi/2 and i want values from 0 to pi
[Edited on October 18, 2008 at 7:03 PM. Reason : ya feel???] 10/18/2008 7:00:50 PM |
NeuseRvrRat hello Mr. NSA! 35376 Posts user info edit post |
oh shit, nevermind, i figured out how to do it with "atan2"
[Edited on October 18, 2008 at 7:10 PM. Reason : thanks for the help and for putting up with the quintuple posts. this is enough tech talk for me lo] 10/18/2008 7:09:26 PM |
moron All American 34142 Posts user info edit post |
would
atan( f(x) - pi ) do what you want too?
[Edited on October 18, 2008 at 7:17 PM. Reason : ] 10/18/2008 7:17:14 PM |
NeuseRvrRat hello Mr. NSA! 35376 Posts user info edit post |
maybe abs(atan(x-pi)), but i'm not sure. i don't think that would've worked either.
i did:
vert=(numerator of stuff i had before) horiz=(denominator of stuff i had before) angle=atan2(vert,horiz)
"atan2" uses -pi to pi and is quadrant specific. it's useful for working with complex numbers in polar form. 10/18/2008 8:22:54 PM |
simonn best gottfriend 28968 Posts user info edit post |
Quote : | ">> run E:\magfac" |
i read that as 'macfag'.10/18/2008 8:31:47 PM |
wdprice3 BinaryBuffonary 45912 Posts user info edit post |
I too, read the error as, "macfag" and thought to myself, "well there's his problem right there!." 10/18/2008 9:15:28 PM |
Wickerman All American 2404 Posts user info edit post |
^^^ Dude u got ur code working yet?
[Edited on October 19, 2008 at 12:00 AM. Reason : ^] 10/19/2008 12:00:24 AM |
NeuseRvrRat hello Mr. NSA! 35376 Posts user info edit post |
i got it figured out.
i was looking over everything and i realized i messed one of the functions up though. not a matlab problem, a not-knowing-vibrations-very-well problem. should be an easy 2 minute fix though. 10/19/2008 12:06:17 AM |