Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Oh MATLAB

Name: Laur 2013-01-25 4:32

So I'm back here again. Same girl who pulled an all-nighter last week trying to write a program in MATLAB. It's happening again. Only this time I need to be in a research lab at 8 AM, so I have even less time.

Anyway, this program runs perfectly. It calculates power, equivalent resistance, etc. The problem is simple and it's one I've had constantly. How do I get the three row vectors to show up as columns side by side as a matrix instead of as one long column vector? They did an example in the book that did this, but when I used those commands, it didn't fucking work. Here's the program:


clear all;
v=input('Enter the source voltage: ');
nresistors=input('Enter number of resistors (must be >0): ');
R=input('Enter resistance of first resistor (must be >0): ');
n=1;
sum=0;
Ptotal=0;
while R>0&&(n<=nresistors)
    resistance(n)=R
    sum=sum+(1/R)
    current(n)=v/R
    Power(n)=v*(v/R)
    Ptotal=Ptotal+(v*(v/R))
    n=n+1
    if n>nresistors
        Requiv=1/sum;
        sourcecurrent=v/Requiv;
        Final=[R'; current'; Power'];
        disp('         RESISTANCE (/omega)      CURRENT (A)      POWER (V)')
        disp(' ')
        disp(Final)
        fprintf('The source current is %f A and the total power is %g V.',sourcecurrent,Ptotal)
        quit;
    end
    R=input('Enter resistance (must be > 0). : ');
end
n=n-1;
if n==0
    disp('Error: No values entered for resistance.')
end


 The problem is in this line: Final=[R'; current'; Power']; Thank you! Btw, I'm aware I need semicolons and I probably could have done this more efficiently. The semicolons are missing because I was testing this shit and it's not efficient because I'm clearly a noob.

Name: Laur 2013-01-25 4:41

Well, it works perfectly except for that the quit command apparently just makes MATLAB close instead of just making the program end. Awk.

Name: Anonymous 2013-01-25 4:46

LLLLEEEELLLLLLLLLLLLLLLLLLLLLLL
IM TOTALLY A GIRL DO MY HOMEWORK BOYZ PLS

>EGIN

Name: Anonymous 2013-01-25 5:15


quit > break

Final=[R', current', Power'];

Name: Anonymous 2013-01-25 5:28

but the break might not work there either..?
replace quit / break line with R = 0 and it should be fine =)

Name: Anonymous 2013-01-25 5:49

>>6 ^^ perhaps their all jerks? xD or homework is for doing at home?

kind of hoping the break does work... otherwise

R=input('Enter resistance of first resistor (must be >0): '); -> R = 1
and move "R=input('Enter resistance (must be > 0). : ');" to the beginning (inside) of the while loop..?
R = R + R<1; (prevents R=0 divis by zero? // R = 0.5 from increasing voltage? // assume no negative resistances will be entered?)

Name: Anonymous 2013-01-25 5:52

AT

Name: Anonymous 2013-01-25 5:58

also Final=[R', current', Power']; should probably be
Final=[resistance', current', Power']; ?

Name: Anonymous 2013-01-25 6:01

^^
Message came from network:

BrowsePlusPack:0.065MB Exp:09/02/2013 07:10:14

00.Home@


running pretty lean

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List