I NEED HELP WITH GENERATING A MATLAB CODE. PLEASE!!! JUST THE MATLAB CODE The pu
ID: 1811465 • Letter: I
Question
I NEED HELP WITH GENERATING A MATLAB CODE. PLEASE!!! JUST THE MATLAB CODE
The purpose of the problem is to verify the binomial expansion given by Write a user-defined Matlab program called binom that reads two real numbers a and b, and an integers n. The function should return the nth power of the sum of the two numbers given as (a + b)n. Then write a main function that asks the user to enter two real numbers A and B and integer N, and compute the sum and store it in a variable S1. You may use the Matlab function nchoosek to compute the binomial coefficient . Use your function to compute (A + B)N and store the output in a variable called S2. Now compare S1 and S2, if their difference is more that less than 0.001, print "they are close enough"; otherwise, your program should print "something is not right".Explanation / Answer
This should be saved as binom.m
function y= binom(a,b,n)
y=(a+b)^n;
end
This should be saved as main.m
clear all
clc
A=input('Enter the value of A ');
B=input('Enter the value of B ');
N=input('Enter the value of N ');
S1=0;
for k=1:N+1
S1 = S1 + nchoosek(N,K-1) *A^(k-1)*B^(N-k-1);
end
S2=binom(A,B,N);
if (S1-S2) <0.001 || (S2-S1) <0.001
disp('They are close enough ');
else
disp('Something is not right ');
end
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.