Passing a matrix as a parameter in ode15s

4 次查看(过去 30 天)
I am trying to pass a matrix of the same dimension as the output value of vx in the code below. I have attached my code for both the script (where the ode15s function is called) and the contents of my called function that returns the output for x_val and vx. Its showing me this error -
Error using odearguments (line 93)
@(X_VAL,VX)ODE_X(X_VAL,VX,VFX) must return a column vector.
The code -
% in the script
psi = norm(vf)*(y-2+m*atan2(y-2,x-2+a)-m*atan2(y-2,x-2-a));
[vfy1,vfx1] = gradient(psi);
vfy= -1*vfy1;% 10 x 10 matrix
vfx = vfx1;% 10 x 10 matrix
vpx0 = 5.*(ones(10,1));
x_range =linspace(1,3,10) ;
[x_val,vx] = ode15s(@(x_val,vx) ode_x(x_val,vx,vfx), x_range, vpx0); % vfx is to be passed as a whole to the ode15s function
% function called
function dvdx = ode_x(x,vx,vfx)
dvdx = (vfx./vx - 1); % here I need to divide each value of vfx by resultant value of vx. But because of inconsistent dimensions I am unable to do that
end
How do I solve this issue ?

采纳的回答

Walter Roberson
Walter Roberson 2020-5-30
function dvdx = ode_x(x,vx,vfx)
dvdx = reshape(vfx./reshape(vx, size(vfx)) - 1), [], 1);
end
  1 个评论
Sanjana Singh
Sanjana Singh 2020-5-30
I am getting this error using this correction-
Error using reshape
To RESHAPE the number of elements must not change.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by