Using vpasolve to solve equation for all values in matrix

10 次查看(过去 30 天)
Is it possible to use vpasolve to solve a particular equation for all values in a matrix without looping? i have a large number of matrices and looping through them all will be very slow.
% Minimal working example
h=rand(5,5);
h_long=reshape(h,[size(h,1)*size(h,2),1]);
store_arr=zeros(numel(h_long),1);
for a=1:numel(h_long)
curr_pix=h_long(a);
tt=vpasolve(5*((1-exp(-5/x)*sind(14))/((1-exp(-5/x))*cosd(14)))==curr_pix, x);
store_arr(a)=tt;
end
fin_mat=reshape(squeeze(store_arr),size(h))
This is a miniature version of what i am doing. my matrix has 4 dimensions and are quite large.
Thanks,
Maria

采纳的回答

Walter Roberson
Walter Roberson 2018-6-4
No, vpasolve() will always consider matrix inputs as being equations to be solved simultaneously.
If you switch to symbolic curr_pix then you can solve() the equation, getting
ttsol = -5./ln(-(-5+curr_pix*cosd(14))./(-curr_pix*cosd(14)+5*sind(14)))
after which you can fin_mat = subs(ttsol, curr_pix, h) to get a matrix of solutions that skips the reshapes()
  3 个评论
Walter Roberson
Walter Roberson 2018-6-4
As long as you have the values of h, then what I showed should work.
h = ... whatever
syms curr_pix x
angd = sym(14);
ttsol = simplify( solve(5*((1-exp(-5/x)*sind(angd))/((1-exp(-5/x))*cosd(angd)))==curr_pix, x) );
fin_mat = subs(ttsol, curr_pix, h);

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Calculus 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by