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
nevermind, i gave up on that so i'm trying to learn matlabin 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
post the function so I know what you are working with
10/18/2008 5:12:52 PM
If all you need to do is plot a function, there are easier ways than matlab.
10/18/2008 5:17:12 PM
ok, i kinda got this figured out. this is my first time using matlab unfortunately.here's my code:w=0:.0001:200;k=4090000c=22800m=2000h=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 oni get this error:>> run E:\magfack = 4090000c = 22800m = 2000??? Error using ==> mpowerMatrix must be square.Error in ==> magfac at 5h=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
this code worked fine for the other function:t=0:.0001:.5;Y=0.1k=4090000c=22800m=2000w=101.81p=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
link[Edited on October 18, 2008 at 5:58 PM. Reason : ]
10/18/2008 5:34:37 PM
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
I googled the error, and it seems you need to use .^
10/18/2008 5:45:09 PM
yeah, i found the .^ thing too, but it still wasn't working. lemme try again.
10/18/2008 5:49:13 PM
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
i didn't even know what the .0001 stood for. someone told me to go with that.
10/18/2008 5:54:49 PM
all i need to do is graph h as a function of w based on the function in line 5code:w=0:.5:200;k=4090000c=22800m=2000h=(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 onoutput a graph with constant h and gave me this in the command window:>> run E:\magfack = 4090000c = 22800m = 2000h = 4.8747e+005that value for h is the value it had on the graph
10/18/2008 5:58:20 PM
Matlab rocks.. I get paid to write matlab code
10/18/2008 5:59:24 PM
^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
hmm... maybe try this as your h, i noticed you left out some .^ and you want to put them in front of the multiplies tooh=(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
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
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
good point. i'm actually supposed to plot the abs. value of that h value anywayi'll give it a try
10/18/2008 6:07:46 PM
this returns the same constant value stuff:w=0:.5:200;k=4090000c=22800m=2000h=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 onas does this:w=0:.5:200;k=4090000c=22800m=2000h=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
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
hell, i tried this and get that same damn graph:w=0:.5:200;k=4090000c=22800m=2000h=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
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
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
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
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
when would you like your cookout tray?
10/18/2008 6:44:13 PM
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
yes, but my home internet is too slow for the remote stuffit'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
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=4090000c=22800m=2000p=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 oni 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
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
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
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
10/18/2008 8:31:47 PM
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
^^^ Dude u got ur code working yet?[Edited on October 19, 2008 at 12:00 AM. Reason : ^]
10/19/2008 12:00:24 AM
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