Simpson's 1/3 Rule
14 views (last 30 days)
Show older comments
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
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
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?
Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!