1. ## Matlab

Hello,

I am not 100% sure if this is the right area to be posting this particular topic. I was wondering how many of you are familiar with Matlab?

Fall term I took one of the basic engineering courses, (ENGR-101). The class was made up of both lecture and lab. In lab we learned how to use Excel 2011 and Matlab 2011a. Even though we have gone over several programs, I still don't feel comfortable trying to troubleshoot programs or design new programs in Matlab. Does it take time to get familiar with the program? How do I familiarize myself with Matlab if there are 100's of commands?

Here is one of the latest programs I troubleshooted with a friend from school who understands Matlab.

% Name: Zach
% Date: 11/23/2012
% Lab: #8
% Purpose of program: This program calculates roots of a quadratic equation

%Clear MATLAB's old Workspace Window variables
clear
%Clear MATLAB's Command Window
clc

% Display the definition of the program
fprintf('\n\n\tAuthor: Zach ');
fprintf('\nThis program calculates roots of a quadratic equation\n')

% Initializing quit variable as 0.
quit = '0';

while(quit == '0')
%Commands user for a inputs
a = input('\n\n\t Enter the value of a: ');
b = input('\n Enter the value of b: ');
c = input('\n Enter the value of c: ');

if(a == 0)
%Display not qudratic message to user
fprintf('\n\t This is not a quadratic, it is a linear equation.')

if(b ~= 0)
%Calculate(assign) root one for linear equation
root1 = -(c/b);
%Display root1 with labeling
fprintf(['\n The linear equation bx + c has an x value of x = ' num2str(root)]);
else
%Display invalid coefficent message
fprintf('\n The you have chosen for a, b, and c are invalid coefficent ');
end
else
%Calculate(assign) variable discriminant
discriminant = b^2 p 4*a*c;

if(discriminant < 0)
%Calculate(assign) real and imaginary part of a complex roots
realpart = -b/(2*a);
imaginary = sqrt(abs(discriminant))/(2*a);
%Caculates roots of a complex roots
root1 = realpart + imaginarpart;
root2 = realpart - imaginarypart;

%Display compex roots 1 and 2 with label
fprintf('\n The coefficent you assigned gives you complex roots ');
fprintf(['\n Root1 = ' num2str(root1)];
fprintf(['\nRoot2 = ' num2str(root2)]);
elseif(discriminant == 0)
%Calculates(assign) root1 of real double root
root1 = -b/(2*a);

%Displays double real root message with labeling
fprintf(['\nThis is a double real root, root = ' num2str(root1)]);
else
%Calculates(assign) two unequal real roots
root1 = (-b + sqrt(discriminant))/(2*a);
root2 = (-b - sqrt(discriminant))/(2*a);

%Displays root 1 and 2 with labeling
fprintf(['\nRoot1 = ' num2str(root1)]);
fprintf(['\nRoot2 = ' num2str(root2)]);
end

end
fprintf('\n\n');
%Prompt user for choice to continue
choice = input('Do another problem? ', 's');

if(choice == 'Y' || choice == 'y')
%Loops Program
quit = '0';
else
%Quits program with message
quit = '1';
fprintf('\nThe program was successful, bye.\n\n');
end
end

Next year I will be taking C/C++. Do you know if C++ is similiar to Matlab?

2. Originally Posted by ME_student
Do you know if C++ is similiar to Matlab?
OK, first, bear in mind, I know nothing about Matlab other than looking at the code you supplied.

There are some similarities between the Matlab code you supplied and C/C++, but there are also a lot of differences. I see no reference to standard Header files and variable declarations seem to be implied rather than defined, no Type definitions. There appears to be no Block bracketing etc.

All in all, it looks to be interpreted code rather than a compiled which can make for a very loose structure, something C/C++ is definitely not.

If you are thinking of taking a course in C/C++ now, to better understand Matlab, then I would say it probably will not help much. But, doing more to understand Matlab now should give you a jump-start in C/C++ for the course next year.

Over many years, I have found that learning another programming language is a very simple process, once you understand programming approach, procedures, portocol and methods learned with your first programming course. The first may have taken many months to understand and get comfortable with, the second may take only a few hours.

If you are already struggling with the Matlab stuff above, then C/C++ is gonna hurt!

Hope that helps with the question.

3. Thanks. I am not looking forward to programming, although things could possibly change. There were a few people in my class who have taken CIS-120 or C++. One of my buddies took CIS-120 before taking Matlab. He seemed to understand the concept pretty well. I am hoping that I will understand the basic programming classes, preparing me for the upper classes like C++. I kind of have a feeling my friend had a better understanding of Matlab than I did because he had take a programming class prior to Matlab.

4. If you can't lean easily into programming, as in, easily understanding what is gong on quickly, then maybe a slight career path change could be beneficial. As I said, if you are struggling with that Matlab cod above then C etc is going to be hard going.

Programming is something you pretty much grasp the idea of quickly or not at all. There is no shame to not quickly understanding programming, different people are good at different things, and that's why a course next year on C/C++ may be more hard work than benefit for you.

I have been programming for 40-years and I have seen a lot of programmers in that time. Between 50% and 60% of them are not good programmers, they are just barely adequate at following "book" procedures. They stuck with programming when they should have looked at a slightly different career path that they were more natural at and enjoyed more.

Good luck with the quest, but sort out what is best for you. You need to learn stuff you love doing and are good at rather than struggling with stuff that you will eventually hate.

5. I agree, but I like to understand programming better. The engineering field I want to join doesn't involve programming, mostly auto CAD and Micro-Station. We will have to see how things go in those classes nextt year. I will definitely let you know how I am doing once I get there. Thanks for the advice.

6. Happy to help, but please note that pretty much everything has Macro-languages (programming) these days. AutoCAD included. It would probably not be a bad idea to give a course on C/C++ a try. Most programming dialects these days are pretty much "C" oriented. In that if you can understand and program in the basic C language, you can pretty much pick up the rest very quickly. Javascript for instance is very C-Like as are the other web languages such as Python, Ruby etc.

The "++" of C++ just implies additions to the basic C language. It makes life a lot easier using C++ because of all of the pre-built extensions and functionality. It still requires a good understanding of the basic C language though. There are many books and free online courses that you can teach yourself C programming. Might not have to wait until next year for that course.

7. Originally Posted by PinkertonD
Happy to help, but please note that pretty much everything has Macro-languages (programming) these days. AutoCAD included. It would probably not be a bad idea to give a course on C/C++ a try. Most programming dialects these days are pretty much "C" oriented. In that if you can understand and program in the basic C language, you can pretty much pick up the rest very quickly. Javascript for instance is very C-Like as are the other web languages such as Python, Ruby etc.

The "++" of C++ just implies additions to the basic C language. It makes life a lot easier using C++ because of all of the pre-built extensions and functionality. It still requires a good understanding of the basic C language though. There are many books and free online courses that you can teach yourself C programming. Might not have to wait until next year for that course.
Okay thank you.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•