Find intersections of two sin wave function
Hi guys,
I am trying to find the intersection points of these two sin waves. I dont know what I did wrong.
f_1=120
f = 0.079
f1 = @(t) 35 * sin(2*pi*f_1*t + 0.08*pi).^2;
f2 = @(t) 35 * sin(2*pi*f*t + 0.08*pi).^2;
tolerance = 1e-5
T=25;
Fs = 44100;
t = 0:1/44100:T-1/44100
plot(t, f1(t), t, f2(t));
xlabel(‘Time (s)’);
ylabel(‘Amplitude’);
title(‘Potential Intersection Regions’);
legend(‘f1(t)’, ‘f2(t)’);
difference = abs(f1(t) – f2(t));
potential_intersections = t(difference < tolerance);
refined_intersections = [];
for i = 1:length(potential_intersections)
p_intersection = potential_intersections(i);
try
intersection_func = @(t) f1(t) – f2(t);
options = optimoptions(‘fsolve’);
options.Tolerance = tolerance;
refined_intersection = fsolve(intersection_func, p_intersection, options);
refined_intersections.append(refined_intersection)
catch ME
if strcmp(ME.identifier, ‘MATLAB:fsolve:NotVectorValues’)
warning(‘fsolve did not converge for guess: %f’, p_intersection);
else
rethrow(ME);
end
end
end
disp("Intersection points (refined):")
disp(refined_intersections)Hi guys,
I am trying to find the intersection points of these two sin waves. I dont know what I did wrong.
f_1=120
f = 0.079
f1 = @(t) 35 * sin(2*pi*f_1*t + 0.08*pi).^2;
f2 = @(t) 35 * sin(2*pi*f*t + 0.08*pi).^2;
tolerance = 1e-5
T=25;
Fs = 44100;
t = 0:1/44100:T-1/44100
plot(t, f1(t), t, f2(t));
xlabel(‘Time (s)’);
ylabel(‘Amplitude’);
title(‘Potential Intersection Regions’);
legend(‘f1(t)’, ‘f2(t)’);
difference = abs(f1(t) – f2(t));
potential_intersections = t(difference < tolerance);
refined_intersections = [];
for i = 1:length(potential_intersections)
p_intersection = potential_intersections(i);
try
intersection_func = @(t) f1(t) – f2(t);
options = optimoptions(‘fsolve’);
options.Tolerance = tolerance;
refined_intersection = fsolve(intersection_func, p_intersection, options);
refined_intersections.append(refined_intersection)
catch ME
if strcmp(ME.identifier, ‘MATLAB:fsolve:NotVectorValues’)
warning(‘fsolve did not converge for guess: %f’, p_intersection);
else
rethrow(ME);
end
end
end
disp("Intersection points (refined):")
disp(refined_intersections) Hi guys,
I am trying to find the intersection points of these two sin waves. I dont know what I did wrong.
f_1=120
f = 0.079
f1 = @(t) 35 * sin(2*pi*f_1*t + 0.08*pi).^2;
f2 = @(t) 35 * sin(2*pi*f*t + 0.08*pi).^2;
tolerance = 1e-5
T=25;
Fs = 44100;
t = 0:1/44100:T-1/44100
plot(t, f1(t), t, f2(t));
xlabel(‘Time (s)’);
ylabel(‘Amplitude’);
title(‘Potential Intersection Regions’);
legend(‘f1(t)’, ‘f2(t)’);
difference = abs(f1(t) – f2(t));
potential_intersections = t(difference < tolerance);
refined_intersections = [];
for i = 1:length(potential_intersections)
p_intersection = potential_intersections(i);
try
intersection_func = @(t) f1(t) – f2(t);
options = optimoptions(‘fsolve’);
options.Tolerance = tolerance;
refined_intersection = fsolve(intersection_func, p_intersection, options);
refined_intersections.append(refined_intersection)
catch ME
if strcmp(ME.identifier, ‘MATLAB:fsolve:NotVectorValues’)
warning(‘fsolve did not converge for guess: %f’, p_intersection);
else
rethrow(ME);
end
end
end
disp("Intersection points (refined):")
disp(refined_intersections) intersection MATLAB Answers — New Questions