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

Must not use existing Matlab functions...only symbolic toolbox. Must be solved v

ID: 3588043 • Letter: M

Question

Must not use existing Matlab functions...only symbolic toolbox. Must be solved via matrix algebra similar to this:

clear;


x = [1 2 3 4 6 7];
y = [2 4 7 1 3 5];
n =3;
m =length(x);
A =zeros(n,n);
a =zeros(n,1); %coefficient matrix
b =zeros(n,1); %solution matrix (Aa=b)

A (1,:) = [m,sum(x),sum(x.^2)]; %force first row
  
%loop for rows 2 through n   
for i=2:n
  
A(i,:) = [sum(x.^(i-1)),sum(x.^(i)),sum(x.^(i+1))];
  
end
%loop for the b matrix
for i=1:n
b(i) = sum(y.*(x.^(i-1)));
end
a= A; %solve for a

scatter(x,y,'k*');

Write Matlab code to implement the continuous least squares method of nding the best-t polynomial of degree n for a given function f on the interval [a, b]. Near the top of your program, hard code n, a, b, and f, where f should be a symbolic variable. Your output should be a picture, showing both the original function f and its least squares polynomial approximation, both only on the interval [a, b].

Explanation / Answer

.text #calculates sum of digits recursively SumDigits: sub $sp, $sp, 12 #alloocate 12B on stack sw $ra 0($sp) #save return address sw $a0, 4($sp) #save argument beq $a0, $0, exit_sumdigits #when there is no more digits return 0 rem $t0, $a0, 10 #get last digit sw $t0, 8($sp) #save it on stack div $a0, $a0, 10 #divide argument by 10 jal SumDigits #repeat procedure lw $t0, 8($sp) #read digit from stack add $v0, $v0, $t0 #add digit to previous result lw $ra, 0($sp) #load return address addi $sp, $sp, 12 #free stack jr $ra #return exit_sumdigits: li $v0, 0 #there are no more digits, return 0 lw $ra, 0($sp) #load return address addi $sp, $sp, 12 #free stack jr $ra #return main: li $a0, 75080 #load number in $a0 jal SumDigits #call SumDigits move $a0, $v0 #set a0 = result of SumDigits li $v0, 1 #set $v0 for print int system call syscall li $v0, 10 #set $v0 for exit system call syscall .data

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Chat Now And Get Quote