EGR 103/Fall 2009/Questions

From PrattWiki
(Redirected from EGR 53/Fall 2009/Questions)
Jump to navigation Jump to search

Lab 5

  • I am making a graph for NormDist.m as part of Lab 5, but I cannot get NormDist to accept a non-square matrix of z values. It treats linspace(-4, 4, 100) as a 100 x 1 matrix. Any hints for how I can graph NormDist? Mjc43 13:46, 12 September 2009 (EDT)
    • It's treating it as a 1 x 100 matrix - and that is correct; be sure to use .* and ./ and .^ in your calculation and it will be fine. DukeEgr93 14:42, 12 September 2009 (EDT)
  • On Problem 5.4.3, I typed in the Manning equation as
    U = (sqrt(S)./n)*((B.*H)/(B+2.*H))^(2/3)
    
    which failed to produce a graph. What is the reason for this?—Preceding unsigned comment added by Xyz2006tor (talkcontribs)
    • That just calculates a value - you have to use the plot command to create a graph. DukeEgr93 00:40, 17 September 2009 (EDT)


  • how do I find the most displacement for a million values? I've run it for like 25 minutes and matlab is still busy. Ruobling 17:09, 17 September 2009 (EDT)
    • The min command certainly should not take that long, even for 1 million values... Is it waiting for you to hit return? DukeEgr93 15:25, 19 September 2009 (EDT)

Lab 6

  • For lab 6, I gave code that clearly defined a function for input x, I can run the function from my command window, but when I run the .m file, it say that variable x is undefined. I look at other examples, and they appear identical without having this problem. What am I doing wrong? Mjc43 00:14, 28 September 2009 (EDT)
    • Generally, specific questions like this should go to one of your four TAs. Please also be sure to let the TA know specifically which file you are talking about. My guess is that you are trying to save a function with the F5 command - if you do that, MATLAB will try to run the function without any inputs (i.e. nargin will be 0) and so your input variables will be undefined in the function. Hitting F5 on a function is like typing
      cos()
      
      there's just no good way for MATLAB to figure out what you want. DukeEgr93 10:32, 28 September 2009 (EDT)
  • Whenever I try to run my first lab 6 program MATLAB freezes up. Even if I copy and paste just a small part of the code into the command window MATLAB doesn't seem to be able to handle anything more than a few numbers/variables at a time. Not sure if this might be related, but a lot of the computers won't let me log in to them either.

Lab 8

  • If I have a row vector that contains a variable number of zeros and a variable number of non-zero real numbers, is there some operation I can do to "remove" the zeros from the vector so that I'm left with only the non-zero elements? e.g. what operation could I use to go from c = [1 0 3 4 0 0] → c = [1 3 4]?Jdr31 14:59, 15 October 2009 (EDT)
    • It's subtle, but:
      c(find(c))
      
      will work. Formally,
      c(find(c~=0))
      
      Note that the result will generally be a column vector in order by index number, so if you do this on a matrix, you will get a vector in return. That's mainly because the answer is not necessarily a rectangular array of data so MATLAB punts. DukeEgr93 09:59, 16 October 2009 (EDT)

Lab 9

  • Question about Plots - When it comes to plotting multiple related relationships, do you mind if we place them on a single plot? This specifically relates to Lab 9, Problem 2, Part 2. Would there be value to directly comparing the two plots? Rjb16 02:03, 25 October 2009 (EDT)
    • For that specific one only, putting both tank 4 and tank 5's concentration on the same graph is fine as long as there is a clear legend. For task 3, you do *not* want to try to put both surfaces in the same graph, though. DukeEgr93 15:03, 25 October 2009 (EDT)

Lab 11

  • Question about interp2- I am quite confident that my code produces my X and Y by a meshgrid, and yet I get the following error message: "X and Y must be matrices produced by MESHGRID. Use GRIDDATA instead of INTERP2 for scattered data." Why would this be? edb10 9:29, 11 November 2009 (EDT)
    • Without seeing the actual code - and it looks like you have changed your code from what it was, I cannot be entirely sure... If you send me an e-mail with what you had, I can take a look and then present a general answer here. DukeEgr93 23:45, 11 November 2009 (EST)