Matrix dimensions do not agree

2 ビュー (過去 30 日間)
jnovv
jnovv 2015 年 12 月 16 日
コメント済み: jnovv 2015 年 12 月 16 日
Hi everyone,
I am wondering if you can help me with this issue.
I have a differential equation code (dy/dt) that is solved using a solver. At the end I got the the dimension of y to be 2868x11.
There is also another parameter called xinf, with it being defined as
xinf = 1/(1+exp(-(y(:,1)-Vx)/kx))
Vx and kx are both constant. At the end, xinf has the dimension of 1x2868.
The issue takes place when I need to calculate this formula:
Ix = gx*xinf.^3.*y(:,2).*(y(:,1)-Ex)
Ex is a constant.
I receive the error saying that the matrix dimensions do not agree. I tried transposing xinf, and although the code runs, it does not produce the output that is desired.
I was wondering is someone can help me solve this issue? Maybe another way to go about this? As I seem to have reached a dead end.
Many thanks in advance!

採用された回答

James Tursa
James Tursa 2015 年 12 月 16 日
My guess is you meant that division in your xinf calculation to be element-wise. E.g., change the / to ./ as follows:
xinf = 1./(1+exp(-(y(:,1)-Vx)/kx))
  1 件のコメント
jnovv
jnovv 2015 年 12 月 16 日
Thank you for your suggestion! Fixed the problem immediately :)

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

その他の回答 (1 件)

the cyclist
the cyclist 2015 年 12 月 16 日
編集済み: the cyclist 2015 年 12 月 16 日
Just stating "it does not produce the output that is desired" is a bit vague. Can you be more specific?
Just a guess, though ... I bet you actually wanted
xinf = 1./(1+exp(-(y(:,1)-Vx)/kx))
rather than
xinf = 1/(1+exp(-(y(:,1)-Vx)/kx))
Notice that I used "./" in place of "/". That also solves your issue with needing to transpose, which gives me a dose of confidence that it was the right operation in the first place.
  1 件のコメント
jnovv
jnovv 2015 年 12 月 16 日
Thank you very much for your help! The output needs to be in form of a graph that is similar to the data obtained from an experiment, which is quite tricky to explain. But your suggestion did fix it!

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

カテゴリ

Help Center および File ExchangeElementary Math についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by