[Solved] Find the value of a variable
Show older comments
Hi. I'm still new using matlab and struggling with a portion of my code. In this phase I need to find the value of a certain variable(s) present in an equation/array. I read about fsolve but it needs to be in a script since I can't do them one by one (and from what I read, I don't think this code can work that way). I would be thankful if someone could help me solve this problem. I only have one variable but if possible I would like to know how to do with more than one.
Thank you in advanced.
example 1 (I want to find x):
f(1)=34;
f(2)=12;
for k=1:2;
x(k,1)^2+3*x(k,2)+4=f(k); %what I want to solve
end
example 2 (I want to find A and B):
g(1,1)=34;
g(1,2)=12;
g(2,1)=100;
g(2,2)=156;
for k=1:2;
A=[4 3; 1 2]*[A(k); B(k)]=[g(k,1); f(k,2)];
end
2 Comments
Lucas Neves
on 27 Dec 2016
Pedro, are you sure this code is complete? I mean, when you say i=1,10 then x=2 you will get x=2 and not =x-2... I'm not getting this clearly but is that all the code? Cheers
Pedro Pires
on 27 Dec 2016
Edited: Pedro Pires
on 27 Dec 2016
Answers (2)
Image Analyst
on 27 Dec 2016
the syntax is not right. Perhaps you meant
for i = 1 : 100
or better yet, use k instead of i, which is the imaginary variable.
Regarding "find x":

Similar for finding A and B.
This line of code has bad syntax with two equal signs.
A=[4 3; 1 2]*[A; B]=[0; 0];
I have no idea what you're attempting. And in both of the loops, there is no change of anything inside as the loop iterates so I don't know what the loop is for.
Pedro Pires
on 27 Dec 2016
Edited: Pedro Pires
on 27 Dec 2016
0 votes
Categories
Find more on Programming in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!