How to solve simultaneous equations?

조회 수: 2 (최근 30일)
Medhanand Kalluri
Medhanand Kalluri 2021년 10월 13일
답변: Bjorn Gustavsson 2021년 10월 14일
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
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)
Medhanand Kalluri
Medhanand Kalluri 2021년 10월 14일
Like is there no tool to solve two equations? I've used fzero for a single variable equation (not system of equations) (but to use that I first entered the function as a string; then used str2func to convert it into a function; then used fzero).
1) Similar to fzero, is there an inbuilt function available? If there is how do we use it for simultaeous functions?
2) For symbolic functions (i.e. if we create f1 and f2 with x1 and x2 defined as sym variables) we can't use fzero, then how do we find the roots?

댓글을 달려면 로그인하십시오.

답변 (1개)

Bjorn Gustavsson
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".

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by