How to solve for a series of variables that intersect with each other?

2 ビュー (過去 30 日間)
Chao Wang
Chao Wang 2019 年 2 月 23 日
コメント済み: Walter Roberson 2019 年 2 月 24 日
Hi folks, recently I got a problem about solving a series of variables which have the property like:
x1 x2 x3 x4 x5 x6 x7 x8 x9 x10, where x1 and x10 are known, and the relationships are as following:
x2=x1^2+x3^3;
x3=x2^2+x4^2;
x4=x3^2+x5^2;
...
Intuitively there are in total 8 unkown variables and 8 equations so we can get value of each of them, but how can I solve these functions in matlab? What if there are more than just 10 variables, say 100, from x1 to x100, how can I solve the functions for x2 to x99? I tried to solve this as solving a system of linear equation but failed.
  5 件のコメント
Chao Wang
Chao Wang 2019 年 2 月 23 日
編集済み: Chao Wang 2019 年 2 月 23 日
I tried as what you said, and this is what I wrote:
M=95;
r=0.02;
q=0;
dt=0.02;
sigma=0.18;
a=zeros(M-1,1);
b=zeros(M-1,1);
c=zeros(M-1,1);
a(1)=M-1;
b(1)=M-1;
c(1)=M-1;
for j=2:M-1
a(j)=a(j-1)-1;
b(j)=b(j-1)-1;
c(j)=c(j-1)-1;
end
for j=1:M-1
a(j)=(r-q)*(M+1-j)*dt/2-sigma^2*(M+1-j)^2*dt/2;
b(j)=1+sigma^2*(M+1-j)^2*dt+r*dt;
c(j)=-(r-q)*(M+1-j)*dt/2-sigma^2*(M+1-j)^2*dt/2;
end
parameter=zeros(M-1,M+1);
for j=1:M-1
parameter(j,j)=c(j);
parameter(j,j+1)=b(j);
parameter(j,j+2)=a(j);
end
b=zeros(94,1);
myfunc=@(x) parameter*[0;x;12]==b;
x=solve(myfunc,x);
but how to claim the dimension of x? If I don't do anything, the system just thinks [0;x;12] is a 3*1 vector rather than 94*1 vector.
Walter Roberson
Walter Roberson 2019 年 2 月 24 日
x = sym('x', [94, 1]);
myfunc = parameter*[0;x;12]==b;
sol = solve(myfunc, x);
X = vpa( struct2cell(sol) );

サインインしてコメントする。

回答 (0 件)

カテゴリ

Help Center および File ExchangeSolver Outputs and Iterative Display についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by