[Solved] Find the value of a variable

조회 수: 11 (최근 30일)
Pedro Pires
Pedro Pires 2016년 12월 26일
편집: Pedro Pires 2016년 12월 27일
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
Lucas Neves
Lucas Neves 2016년 12월 27일
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
Pedro Pires 2016년 12월 27일
편집: Pedro Pires 2016년 12월 27일
Thank you for the message. You're right. This isn't my code but I wanted to keep it simple so I made these. Didn't look carefully enough and made some mistakes. I think that they have been corrected.
Edit: I solved the problem already. I tried to use solve() before but wasn't able to run it because i didn't use the syms command.

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

답변 (2개)

Image Analyst
Image Analyst 2016년 12월 27일
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
Pedro Pires 2016년 12월 27일
편집: Pedro Pires 2016년 12월 27일
Ahah. Thank you for the answer either way. I think the mistakes have been corrected.

카테고리

Help CenterFile Exchange에서 Programming에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by