How the increment size would affect solving an equation ?
Show older comments
I have a function, and this function should calculate simple equation in a range from 0 to pi/2; the main issue is that I would like to have accurate results, and this require small increment. Here is the function:
function [Sg_wk]=MM(M1,delta)
Y=1.4;
Sg=0:0.001:pi/2;
Del=zeros(1,length(Sg));
for i=1:1:length(Sg)
Del(i)=atan((2*cot(Sg(i))*(M1^2*sin(Sg(i))^2-1))/( 2+M1^2*(Y+cos(2*Sg(i)))));
end
Sg_wk=interp1(rad2deg(Del), rad2deg(Sg), delta, 'linear');
end
If I run this code with >> MM(2,4) ans = 48.6861
The correct answer is 33.39024 If I use the same code with smaller increment (Sg=0:0.1:pi/2), it provides: >> MM(2,4)
ans = 33.4677
much better, but does not that contradict the logic ???
Also, Del now will be calculated, how can extract only the positive values out of the whole matrix ?
Accepted Answer
More Answers (0)
Categories
Find more on Least Squares 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!