0% found this document useful (0 votes)
2 views2 pages

Solve y = x*sin(x) and y = 1-x^2

The document outlines the solution to the system of equations y = x * sin(x) and y = 1 - x^2 by defining a function and using fzero to find the roots. The positive root is approximately 0.722588 and the corresponding y value is 0.477867, with a negative root of -0.722588. A graphical representation is provided to illustrate the intersection of the two functions.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views2 pages

Solve y = x*sin(x) and y = 1-x^2

The document outlines the solution to the system of equations y = x * sin(x) and y = 1 - x^2 by defining a function and using fzero to find the roots. The positive root is approximately 0.722588 and the corresponding y value is 0.477867, with a negative root of -0.722588. A graphical representation is provided to illustrate the intersection of the two functions.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

1) Solve the system of equations y = x * sin(x); y = 1 - x ^ 2 Check the accuracy of your Provide a graphical

interpretation of the solution.

% Define the function f(x) = x*sin(x) + x^2 - 1


f = @(x) x.*sin(x) + x.^2 - 1;

% Find positive root using fzero


x0 = 0.7; % initial guess
root_pos = fzero(f, x0);
root_neg = -root_pos;

% Display roots
fprintf('Root 1: x = %.6f\n', root_pos);

Root 1: x = 0.722588

fprintf('Root 2: x = %.6f\n', root_neg);

Root 2: x = -0.722588

% Compute y values
y1 = root_pos * sin(root_pos);
y2 = root_neg * sin(root_neg); % same as y1 since even function

fprintf('Corresponding y = %.6f\n', y1);

Corresponding y = 0.477867

% Visualization
x = linspace(-2, 2, 1000);
y_curve1 = x .* sin(x);
y_curve2 = 1 - x.^2;

figure;
plot(x, y_curve1, 'b', 'LineWidth', 1.5); hold on;
plot(x, y_curve2, 'r', 'LineWidth', 1.5);
plot(root_pos, y1, 'ko', 'MarkerSize', 8, 'MarkerFaceColor', 'g');
plot(root_neg, y2, 'ko', 'MarkerSize', 8, 'MarkerFaceColor', 'g');
grid on;
xlabel('x');
ylabel('y');
legend('y = x sin(x)', 'y = 1 - x^2', 'Solutions', 'Location', 'best');
title('Intersection of y = x sin(x) and y = 1 - x^2');
hold off;

1
2

You might also like