How to change the value of a variable?

1 view (last 30 days)
ASAD Ullah
ASAD Ullah on 6 Nov 2015
Commented: Walter Roberson on 7 Nov 2015
i have following simple code which solves two equations for two unknowns, the two equations are 2*x(1)+x(2)-4 and x(1) +2*x(2)-5 in which x(1) and x(2) are unknowns and the below code gives the values of unknowns that,s fine. Now i want to make this code flexible in a sense that the program should take different values of x(1) and x(2) so that i can verify the equations using different values of the two unknowns. for example using x(1)=1 and x(2)=2 the equations give 4 and 5 respectively, in the next iteration i should be able to give different values of x(1) and x(2) to verify it,
here is the code
function F = myfun(x)
F = [2*x(1) + x(2) - 4;
x(1) + 2*x(2) - 5];
end
clc;
clear;
close all;
x0 = [1; 2];
fsolve(@myfun,x0)
kindly help, Regards Asad
  1 Comment
Walter Roberson
Walter Roberson on 7 Nov 2015
I do not understand? With x(1) = 1 and x(2) = 2 then the equations appear to give [0 0], which you can verify by calling myfun([1 2])

Sign in to comment.

Answers (0)

Categories

Find more on Systems of Nonlinear Equations 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!