Tutor profile: Gowtham S.
How do you solve a quadratic equation using MATLAB? Discuss various possibilities? Assume a general quadratic function to be f(x) = a x^2 + b x + c
1. The 'solve' function can be used which returns both the solutions of a quadratic equation in an array. Please read the comments to know why that particular command is executed. eq = 'a * x^2 + b*x + c = 0'; % Equation declared soln = solve(eq); % Calling solve function and storing the results in 'soln' variable disp('The first root is: '), disp(soln(1)); disp('The second root is: '), disp(soln(2)); 2. The 'roots' command returns the root of the polynomial passed to it. You can find additional insights in the comments poly = [a b c]; soln = roots(poly); disp('The first root is: '), disp(soln(1)); disp('The second root is: '), disp(soln(2)); Both the method discussed above works well for simple problems. But when the computations are complex, it is better to use the 2nd option because it is a dedicated solver for polynomial roots, unlike a general 'solve' tool. It is also important to note that 'solve' command can be used with symbolic variables too. Yes, not just numbers, it can work well with the alphabets too.
Subject: C++ Programming
How do you read in only the last name of "John Smith" from a file or from the user-input?
I'll discuss various strategies that can be followed and I'll list down their efficiency too. 1. Typical answer, using 1 temporary variable for first name (Not memory efficient) scanf("%s %s", temp, last_name); 2. Another solution, but with 2 scanf() calls (memory efficient, but not time) scanf("%s", last_name); scanf("%s", last_name); 3. Tricky and efficient solution. If you want to skip some input use * sign after %. That is scanf("%*s %s", last_name); This 3rd solution would do the job efficiently. Good code should be a simpler one, doing the job in a straightforward way.
Subject: Aerospace Engineering
We tend to see the fluid flow accelerating when it passes through a convergent tube (you might have observed this while blocking the garden hose with your hand). But every single rocket employs a divergent nozzle (See for example: Atlas V rocket). Why is that so? Do we want the flow to slow down?
Yes, all the rocket nozzles diverge at the end. In garden hoses, the fluid flow is governed by the in-compressible phenomena. While in the case of the rockets, the plot changes totally. The theory of compressible flow suggests the usage of Convergent-Divergent nozzle to accelerate a compressible fluid. This is employed and what you see in the rockets is just the exit of the nozzle (a divergent section). Yeah! After all, it's rocket science.
needs and Gowtham will reply soon.