Using vpasolve to solve equation for all values in matrix
11 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Maria
el 4 de Jun. de 2018
Comentada: Maria
el 5 de Jun. de 2018
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
0 comentarios
Respuesta aceptada
Walter Roberson
el 4 de Jun. de 2018
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 comentarios
Walter Roberson
el 4 de Jun. de 2018
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);
Más respuestas (0)
Ver también
Categorías
Más información sobre Symbolic Math Toolbox en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!