Question

Question 4 MATLAB a) Write a function file called q4.m containing the following nonlinear equations. ?(?1?2...

Question 4 MATLAB

a) Write a function file called q4.m containing the following nonlinear equations. ?(?1?2 ) = ?1 2 + ?2 2 − 26

?(?1?2 ) = 3?1 2 + 25?2 2 − 100 (1 Mark)

b) Use MATLAB’s FSOLVE operator to solve these equations with x1 = 2 and x2 = 2 as your starting point. How many iterations did MATLAB use to solve them? (1 Mark)

Homework Answers

Answer #1

Answer 4:

Part (a)

%% Part (a) q4.m file

function f = q4(x)
    f(1) = x(1)^2 + x(2)^2 - 26;
    f(2) = 3*x(1)^2 + 25*x(2)^2 - 100;
end

Part (b)

%% Part (b)

% Get the function from q4.m
F = @q4;
% Given starting points
x1 = 2;
x2 = 2;
% Solve the function
[x, fval, exitflag, output] = fsolve(F, [x1, x2]);
% Print the solution
fprintf("The solution for F is\n");
fprintf("\tx1 = %f\n", x(1));
fprintf("\tx2 = %f\n", x(2));
fprintf("The number of iterations is %d\n", output.iterations);

Output:

Kindly rate the answer and for any help just drop a comment

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
I need MATLAB code no handwritten solution required. Write a MATLAB script to solve the following...
I need MATLAB code no handwritten solution required. Write a MATLAB script to solve the following equations using the Cramer’s rule, and compare your results with MATLAB’s root finding method ( 25 pts. ). 8x1 − 2x2 − 1x3 = 5 − 2x1 + 9x2 − 4x3 − x4 = 2 − x1 − 3x2 + 7x3 − x4 − 2x5 = 1 − 4x2 − 2x3 + 12x4 − 5x5 = 1 − 7x3 − 3x4 − 15x5 =...
Solve the following system of nonlinear equations: ?(?,?)=?2 +2x+2?2 -26 ?(?,?)=2?3 -?2 +4y-19 Use Newton-Raphson method....
Solve the following system of nonlinear equations: ?(?,?)=?2 +2x+2?2 -26 ?(?,?)=2?3 -?2 +4y-19 Use Newton-Raphson method. Carry out the first five iterations, startingwith? =1and? =1.
Write a MATLAB m file to plot the 3-D curve represented by a multivariable function z(x,y)...
Write a MATLAB m file to plot the 3-D curve represented by a multivariable function z(x,y) = x2 −0.5y2 over x ∈ [−2,2] and y ∈ [−2,2]. Use a 2 point thickness. For both x an y axes, choose the grid size to be 0.05. Clearly label and title your plot. Rotate the view at an azymuth of −20 , and elevation of 20 . You need to use the following commands: x=-2:0.05:2; y=x; z=x.^2-0.5*y.^2; plot3(x,y,z,’LineWidth’,2) label(’ My 3D curve’);...
MATLAB: Do the following with the provided .m file (a) In the .m file, we have...
MATLAB: Do the following with the provided .m file (a) In the .m file, we have provided three questions. Make sure to answer them. (b) Now on the MATLAB prompt, let us create any two 3 × 3 matrices and you can do the following: X=magic(3); Y=magic(3); X*Y matrixMultiplication3by3(X,Y) (c) Now write a new function in MATLAB called matrixMultiplication that can multiply any two n × n matrix. You can safely assume that we will not test your program with...
MATLAB: Do the following with the provided .m file (a) In the .m file, we have...
MATLAB: Do the following with the provided .m file (a) In the .m file, we have provided three questions. Make sure to answer them. (b) Now on the MATLAB prompt, let us create any two 3 × 3 matrices and you can do the following: X=magic(3); Y=magic(3); X*Y matrixMultiplication3by3(X,Y) (c) Now write a new function in MATLAB called matrixMultiplication that can multiply any two n × n matrix. You can safely assume that we will not test your program with...
2. 2052 Write a function in MATLAB called HTBALL to calculate the height of a ball...
2. 2052 Write a function in MATLAB called HTBALL to calculate the height of a ball based on a single input, the elapsed time. The elapsed time will be a single variable in the range of 0 to 6. Predict the value by fitting a 2nd order polynominal to the data points shown below using the polyfit command. Use the command polyval to determine the height of the ball at the inputted time. timevals=[0,.5,1,1.5,2,2.5,3,3.5,4,4.5,5,5.5,6]; height=[0,46,84,114,136,150,156,154,144,126,100,66,24]; Copy and paste the data...
Solve the following problem using the MATLAB environment Write a function [approx_root, num_its] = bisection(f,a,b,tol) that...
Solve the following problem using the MATLAB environment Write a function [approx_root, num_its] = bisection(f,a,b,tol) that implements the bisection method. You function should take as input 4 arguments with the last argument being optional, i.e, if the user does not provide the accuracy tol use a default of 1.0e-6 (use varargin to attain this). Your function should output the approximate root, approx_root and the number of iterations it took to attain the root, num_its. However, if the user calls the...
1. In a separate JS file, write a function to calculate gross wages for an hourly...
1. In a separate JS file, write a function to calculate gross wages for an hourly employee. The function should receive two parameters: the pay rate (dollars per hour, a floating point number) and the hours worked. Hours from 0 through 40 are “straight time” pay, and any hours in excess of 40 are overtime pay at 1.5 times the standard rate (hint: use the ? : operator to make a decision about pay rates). The function should return a...
Part 2: Solve the following problems in MATLAB 1. Fill in the function E = myElim(A,...
Part 2: Solve the following problems in MATLAB 1. Fill in the function E = myElim(A, r_entry, r_pivot, c) to create an m by m elimination matrix ??. Remember that an elimination matrix looks like an identity matrix with one extra entry of ?? in row r_entry and column r_pivot. 2. Fill in the function M = myMult(A, c_pivot) to create an m by m multiplier matrix ??. Remember that a multiplier matrix looks like an identity matrix with the...
Arrays, loops, functions: Lotto Element Repeated Function Write a function that that takes as parameters an...
Arrays, loops, functions: Lotto Element Repeated Function Write a function that that takes as parameters an array of ints, an int value named element, and an int value named end. Return a bool based on whether the element appears in the array starting from index 0 and up to but not including the end index. Generate Random Array Write a function that takes as parameters an array of integers and another integer for the size of the array. Create a...