Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write required procedures for computing the results of a cubic equation and grap

ID: 3841196 • Letter: W

Question

Write required procedures for computing the results of a cubic equation and graphically displaying the results in the console window. A source file has been included to use as a starting point. You will need to do the following:

PART 1: Put in the code for the SolveForAandB procedure (35 points)
PART 2: Put in the code for the LinearEquation procedure (15 points)
PART 3: Put in code to compute the X increment value. (15 points)
PART 4: Put in the code for the CubicEquation procedure. (35 points)


INCLUDE Irvine32.inc

; The prototypes that the Plotter procedure calls are defined here.
INCLUDE prototypes.inc

; Local prototypes
CubicEquation PROTO, pY:PTR REAL8, x:REAL8
SineFunction PROTO, pY:PTR REAL8, x:REAL8

.data
; Cubic equation coefficients
coeffA REAL8 0.4
coeffB REAL8 1.4
coeffC REAL8 -4.0
coeffD REAL8 -6.4

windowTitle BYTE "0.4x^3 + 1.4x^2 - 4.0x -6.4",0

; Ranges for cubic plot
x0 REAL8 -10.0
x1 REAL8 10.0
y0 REAL8 -10.0
y1 REAL8 10.0

; Ranges for sine function plot
xsin0 REAL8 ?
xsin1 REAL8 ?
ysin0 REAL8 -2.0
ysin1 REAL8 2.0
fval4 REAL8 4.0

.code
main PROC
   ; Initialize the FPU
   finit

   ; You can set the foreground and background colors
   mov       eax, yellow + (blue * 16)
   call   SetTextColor

   ; First develop and debug SolveForAandB
   ; You can check your values at http://www.webmath.com/equline1.html

   ; Then develop and debug LinearEquation

   ; etc.

   ; You call Plotter with the X & Y ranges, and the offset
   ; to the procedure calculating the Y values.
   ; Try this once your procedures are working.
   ;INVOKE Plotter, x0, x1, y0, y1, OFFSET windowTitle, OFFSET CubicEquation

   ; You can plot another function in the same program,
   ; and use different ranges.
   ; You need to define the xsin0 and xsin1 values to use this.
   ;INVOKE   Plotter, xsin0, xsin1, ysin0, ysin1, OFFSET windowTitle, OFFSET SineFunction

   exit
main ENDP

;-------------------------------------------------------------
; You can store a floating point value into a location ESI is
; pointing to as follows:
; fstp   REAL8 PTR [esi]  
;-------------------------------------------------------------

;-------------------------------------------------------------
SolveForAandB PROC USES esi,
   xReal0:REAL8, ; x0 as real
   xReal1:REAL8, ; x1 as real
   yReal0:REAL8, ; y0 as real
   yReal1:REAL8, ; y1 as real
   pA:PTR REAL8, ; Pointer to A for storing result
   pB:PTR REAL8 ; Pointer to B for storing result
; Returns A and B coefficients for linear equation.
;-------------------------------------------------------------
; PART 1: Put in the code for the SolveForAandB procedure
   ; The following is needed to keep the assembler from complaining
   ; Remove it and put in your code for the cubic function.
   fld       xReal0
   fstp   xReal0
   fld       xReal1
   fstp   xReal1
   fld       yReal0
   fstp   yReal1
   mov       esi, pA
   mov       esi, pB

   ret
SolveForAandB ENDP

;----------------------------------------------------------
LinearEquation PROC USES esi eax,
   pYReal:PTR REAL8,   ; Pointer to y as real value
   xReal:REAL8,       ; x as real value
   a:REAL8,
   b:REAL8
;
; Computes the following equation:
; y = a * x + b
;----------------------------------------------------------
; PART 2: Put in the code for the LinearEquation procedure
   ; Remove the following and put in your code for the linear equation

   ; y = x
   fld       xReal
   mov       esi, pYReal
   fstp   REAL8 PTR [esi]

   ; The following is needed to stop the assembler from complaining
   fld       a
   fstp   a
   fld       b
   fstp   b

   ret
LinearEquation ENDP

Linear euqation: y 3x Press any key to continue

Explanation / Answer

The present instructional exercise bargains solely with numerical techniques for settling logarithmic and trigonometric conditions, both single and a few all the while, both direct and non-linear. Analytical arrangements can be gotten utilizing the strategies portrayed in the typical.   When both typical and numerical techniques work, once in a while one is more straightforward and at times the other.
Keeping in mind the end goal to profit by the accompanying material one must duplicate and glue the demonstrated charges into MATLAB and execute them. These summons are appeared in the configuration >> help plot, for example. The client ought to look into each summon in MATLAB's assistance so as to comprehend the order and the distinctive conceivable linguistic uses that can be utilized with it.
Graphical arrangement of one non-direct condition or two non-straight conditions in unequivocal frame
At the point when a solitary condition or a couple of conditions is to be understood, it is great practice to first make a plot. thusly, it can be seen instantly what the surmised arrangement is.
With a specific end goal to plot a condition utilizing the "plot" order it must be in the unequivocal frame, i.e. y = f(x). If the condition can be composed just in verifiable shape, i.e. f(x,y) = 0, then the "ezplot" charge must be utilized as depicted in the typical instructional exercise.
We look at first as a solitary condition, i.e. f(x) = 0. for instance we will utilize sin2(x) e-x/2 – 1 = 0. Do the accompanying strides:
While discretionary, it's a smart thought to clear the Workspace memory with a specific end goal to maintain a strategic distance from the shot of MATLAB utilizing a past incentive for a variable:
>> clear
Figure the scope of x values over which you expect an answer and produce values for the x vector over this range. Select an augmentation sufficiently little to yield a smooth curve. For instance:
>> x = - 10:0.01:10;
gives x from - 10 to +10 in augmentations of 0.01.
Produce the y = f(x) vector relating to these x values:
>> y = sin(x).^2.*exp(- x/2) - 1;
See the dabs before ^ and *. These dabs are essential. Because x is a vector, we should utilize cluster operations as opposed to scalar operations (without the spot).
Likewise make a line for y = 0. The convergence of this line with the bend above gives the arrangement (or arrangements, as in this example). To do this we make a vector with an indistinguishable number of qualities from x, with each esteem being 0.
>> y0 = zeros(1,length(x));
Make the plot:
>> plot(x,y,x,y0);
Find the solution(s). If the two lines don't cross, rehash with another range for x. In our illustration, the lines meet more than once, and we construe, actually, that there are vastly numerous answers for negative x. Let us select the arrangement at about x = - 1.   Enlarge this region of the convergence in the Figure window by Tools/Zoom In, and after that clicking close to the convergence once or more. Then go to Tools/Data Cursor. Click as close as you can to the intersection. Write the outcome down to contrast and that gotten by utilizing the "fzero" summon underneath.
Next let us consider a couple of unequivocal conditions, y = sin2(x) e-x/2 – 1 and y = 10sin(x)/x. Proceeding as above:
>> clear; x = - 10:0.01:10;   y1 = 10*sin(x)./x;   y2 = sin(x).^2.*exp(- x/2) - 1; plot(x,y1,x,y2);
Again we see that there are numerous arrangements (crossing points), both positive and negative. (Note that when MATLAB computed sin(0)/0 it gave a notice, however in any case finished alternate estimations and the plot.) As above, locate the inexact arrangement at x close to 3.5. (I get x = 3.49, y = 0.9796.) Write down your outcome to contrast with those with be discovered later. Alternately, we can liken these two conditions (since both = y), move everything to one side hand side, and discover the estimations of x when this is 0.   For the estimation of x found, the comparing an incentive for y is controlled by substituting this once more into both of the first conditions.
>> clear; x = - 10:0.01:10;   yeq = 10*sin(x)./x - sin(x).^2.*exp(- x/2)+1;
>> yeq0 = zeros(1,length(x));   plot(x,yeq,x,yeq0);
Utilizing an indistinguishable strategy from above, I again got x = 3.49 and yeq = 0.   Note that yeq is not y. To discover the y we substitute x over into both of the synchronous conditions, which gives us two results. (Use your own estimation of x as opposed to my estimation of 3.49.)
>> clear; x = 3.49; y1 = 10*sin(x)/x,   y2 = sin(x)^2*exp(- x/2) - 1
The nearer these are y1 and y2, the better our answer.
Numerical arrangement of maybe a couple non-direct conditions in unequivocal frame (y = f(x))
We utilize the "fzero" order, which finds the estimation of x for f(x) = 0. (See >> help fzero.) We will utilize an indistinguishable cases from above. To show the outcome to 14 critical figures we initially change the configuration to long. For the single condition, sin2(x) e-x/2 – 1 = 0:
>> clear; design long; x = fzero('sin(x)^2*exp(- x/2)- 1', - 1)
(See that no speck is required now before ^ or *, in spite of the fact that utilizing the spot causes no problem.) How does this outcome contrast with the inexact outcome you acquired by the graphical strategy above?
Presently we again consider the combine of conditions, y = sin2(x) e-x/2 – 1 and y = 10sin(x)/x:
>> clear; x = fzero('10*sin(x)/x - sin(x)^2*exp(- x/2) + 1', 3.5)
>> y1 = 10*sin(x)/x,   y2 = sin(x)^2*exp(- x/2) - 1
As some time recently, we see that the numerical technique is more accurate. So why trouble with the graphical strategy at all? The reason is, to see about where you need "fzero" look for an answer!
Finding a specific arrangement when there are boundlessly numerous
There are conditions with an interminable number of arrangements, for instance sin(x) = 1/2.
It is useful to see some of these arrangements by plotting y = sin(x) - 1/2 and after that watching where y has estimations of zero:
>> clear, syms x; eq='y - sin(x) + 1/2'; ezplot(eq,[-6,6,- 2,1])
>> hang on; eq0='0'; ezplot(eq0); hold off
The "hang on" order advises MATLAB to compose the ensuing plots on top of the first, as opposed to supplanting it. Plotting 0 puts a flat line on the graph. Intersections of the sine wave with this line speak to arrangements of the primary equation. Approximate qualities can be acquired in the Figure window by tapping on Tools/Zoom In, tapping on a coveted convergence to amplify that territory of the diagram, tapping on Tools/Data Cursor, and afterward tapping on that crossing point again to give the surmised estimations of x and y there. Try this on the initial two convergences to one side of the inception (x > 0). Write down your outcomes to contrast and those found underneath.
Here are the means to discover an answer numerically:
Change over the condition to a capacity comprising of everything moved to one side hand side, e.g. func2(x) = sin(x)- 1/2.
Make this capacity in the MATLAB editorial manager, spare to the Current Directory, and make certain the present catalog is in the way (File/Set Path). For instance:
work out = func2(x)
out = sin(x) - 1/2;
end
Plot this capacity over the scope important to see where the arrangements are, e.g.:
>> clear, x = - 4:0.01:4; plot(x,func2(x))
Utilize one of the accompanying configurations to discover the arrangement:
>> fzero('func2',3) or >> fzero(@func2,3) or >> fzero('func2', [2,3])
MATLAB finds the estimation of x closest 3 that gives func2 = 0. Notice ("whos" or Workspace) that the outcome is twofold, so no transformations are vital for consequent numeric figurings.
Numerical arrangement of at least two conditions in certain structures (e.g., f1(x,y)=0, f2(x,y)=0)
We utilize the "fminsearch" command. Consider for instance the accompanying two verifiable conditions (as of now in MATLAB arrange):
0.5 = (200+3*x+4*y)^2/((20+2*x+3*y)^2 * x)
10 = (20+2*x+3*y)*y/x
Utilize the accompanying strides:
Move everything to one side hand side in all conditions.
Utilizing MATLAB's alter window, make a capacity that computes the deviations from 0 when self-assertive qualities are utilized for the variables. The last yield of the capacity is the total of the squares of these deviations. Following is the code for our case, and would be spared as meth_reac.m in MATLAB's Current Directory, which should likewise be in the Path (File/Set Path).
work out=meth_reac(guesses)
% capacity to ascertain the estimations of x and y
% fulfilling the two equibiliubrium relations
% for a methanol reactor, CO + 2H2 = CH30H
% CO2 + 3H2 = CH3OH + H2O (coal to chems contextual analysis)
% x is the molar stream rate of CO, y of CO2 (kmol/h)
% After sparing: >> fminsearch('meth_reac',[25,3]); x=ans(1), y=ans(2)
% Any positive qualities function as introductory estimates in this case
x=guesses(1); y=guesses(2);
eq1 = 0.5 - (200+3*x+4*y)^2/(20+2*x+3*y)^2/x;
eq2 = 10 - (20+2*x+3*y)*y/x;
out=eq1^2+eq2^2;
end
3.     In the Command window, sort "fminsearch('function name',[guessed values]). For our case,
>> fminsearch('meth_reac',[25,3]); x=ans(1), y=ans(2)
You can check your come about by utilizing the typical "comprehend" charge, as takes after for our case:
>> clear, syms x y
>> eq1='0.5=(200+3*x+4*y)^2/(20+2*x+3*y)^2/x'
>> eq2='10=(20+2*x+3*y)*y/x'
>> [x y]=solve(eq1,eq2,x,y)
Take note of that few arrangements are created, from which you need to choose the physically sensible one. If this is the primary arrangement, then to acquire twofold accuracy numerical factors we utilize:
>> x=double(x(1)), y=double(y(1))
(The conditions in this illustration depend on the harmony connections for a concoction reactor making methanol from CO, CO2 and H2 as a major aspect of a current plant that creates an assortment chemicals beginning with the gasification of coal, i.e. coal responding with water at high temperature.)

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote