[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 Center および File ExchangeProgramming についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by