![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/766801/image.png)
How to solve simultaneous equations?
1 次查看(过去 30 天)
显示 更早的评论
How to solve simultaionsequations such as this,
f1(x1,x2) = x1^2 + x1*x2 - 10;
f2(x1,x2) = x2 + 3*x1*x2^2 - 57;
with and without using symbolic functions for f1 and f2. Please do explain the process.
2 个评论
Image Analyst
2021-10-13
Do you mean you want to do it numerically? Like with some specific, discrete values for x? What range of x do you want to cover?
clc; % Clear the command window.
fprintf('Beginning to run %s.m ...\n', mfilename);
close all; % Close all figures (except those of imtool.)
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 20;
numPoints = 50;
X1 = linspace(-5, 5, numPoints);
X2 = linspace(-2.5, 2.5, numPoints/2);
[x1, x2] = meshgrid(X1, X2);
f1 = x1.^2 + x1.*x2 - 10;
f2 = x2 + 3*x1.*x2.^2 - 57;
subplot(2, 2, 1);
imshow(f1, [], 'XData', [min(x1), max(x1)], 'YData', [min(x2), max(x2)])
axis('on', 'xy')
impixelinfo
title('f1', 'FontSize', fontSize);
xlabel('x1', 'FontSize', fontSize);
ylabel('x2', 'FontSize', fontSize);
subplot(2, 2, 2);
imshow(f2, [], 'XData', [min(x1), max(x1)], 'YData', [min(x2), max(x2)])
axis('on', 'xy')
impixelinfo
title('f2', 'FontSize', fontSize);
xlabel('x1', 'FontSize', fontSize);
ylabel('x2', 'FontSize', fontSize);
diffImage = abs(f1 - f2);
subplot(2, 2, 3);
imshow(diffImage, [], 'XData', [min(x1), max(x1)], 'YData', [min(x2), max(x2)])
axis('on', 'xy')
impixelinfo
title('abs(f2 - f1)', 'FontSize', fontSize);
xlabel('x1', 'FontSize', fontSize);
ylabel('x2', 'FontSize', fontSize);
subplot(2, 2, 4);
surf(x1, x2, diffImage, 'EdgeColor','none')
title('f2 - f1', 'FontSize', fontSize);
xlabel('x1', 'FontSize', fontSize);
ylabel('x2', 'FontSize', fontSize);
g = gcf;
g.WindowState = 'maximized'
minValue = min(diffImage(:))
[rows, columns] = find(diffImage == minValue)
x1AtMin = X1(columns)
x2AtMin = X2(rows)
subplot(2, 2, 3);
hold on;
plot(x1AtMin, x2AtMin, 'r*', 'LineWidth', 2, 'MarkerSize', 30)
subplot(2, 2, 4);
hold on;
plot3(x1AtMin, x2AtMin, minValue, 'r*', 'LineWidth', 2, 'MarkerSize', 30)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/766801/image.png)
回答(1 个)
Bjorn Gustavsson
2021-10-14
Using symbolic tools you have solve - look at the help and documentation for that function for examlpes. Your problem should reduce to a cubic polynomial so should be possible to check "semi-manually".
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Oil, Gas & Petrochemical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!