Simpson's 1/3 Rule

14 views (last 30 days)
Jack Harker
Jack Harker on 30 Nov 2020
Edited: VBBV on 29 Mar 2024
if mod(n,2) == 1
disp('Simpsons Rule cannot be applied when an odd number of intervals is chosen')
return
else
int = (n-2)/2;
Coefficients = [1, repmat([4 2],1,int),4,1];
end
I am using the loop above to create the coefficents required to apply Simpson's 1/3 rule but I keep getting an error at the end of my code that says," Unable to perform assignment because the left and right sides have a different number of elements." I feel that the error is caused by the repmat statement which is creating a row vector that is too large. My output vector is supposed to have 5 values if this helps. Let me know if you need additional information and thank you in advance!!
  5 Comments
KALYAN ACHARJYA
KALYAN ACHARJYA on 30 Nov 2020
Once I checked, I couldn't get any such error, by passing different n value (Assumed n is single value)
n=.....? Define n here
if mod(n,2) == 1
disp('Simpsons Rule cannot be applied when an odd number of intervals is chosen')
return
else
int = (n-2)/2;
Coefficients = [1, repmat([4 2],1,int),4,1];
end
Abhishek Kumar
Abhishek Kumar on 4 Dec 2020
Hi Jack, the portion of code you have shared has no issues. In the problem statement you are refering to a loop but the code you have shared has no loops. Could you please share the code and exact error you are getting so that we could help you better?

Sign in to comment.

Answers (0)

Categories

Find more on Just for fun in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!