Using vpasolve to solve equation for all values in matrix
2 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
Risposta accettata
Walter Roberson
il 4 Giu 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 Commenti
Walter Roberson
il 4 Giu 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);
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Calculus in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!