# hi i am trying to get the output of this loop in one matrix to use it in another function can anyone help me ?

1 view (last 30 days)
Mohamed Atef on 28 Dec 2022
Edited: Torsten on 29 Dec 2022
syms d
v1=1;
z=acos(0.9);
x12=.06;
v=[ 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 .9 1];
for v2=0:0.1:1 ;
sol= solve((v2/.06)*tan(z)*sin(d)==(v2/.06)*cos(d)-((v2*v2)/.06),d);
s=sol;
s2=double(s);
p=(v2/0.06)*sin(s2);
p2=double(p);
end

Torsten on 29 Dec 2022
Edited: Torsten on 29 Dec 2022
z = acos(0.9);
v = [ 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 .9 1];
% d = -z + acos(v*cos(z)) is (one) solution of (v/0.06)*tan(z)*sin(d)==(v/0.06)*cos(d)-v^2/0.06
% Any d + 2*pi*k (k integer) is also a solution. But since sin(d) is taken later, it doesn't matter.
d = -z+acos(v*cos(z));
p = v/0.06.*sin(d);
plot(v,p)
grid on
##### 2 CommentsShowHide 1 older comment
Torsten on 29 Dec 2022
Edited: Torsten on 29 Dec 2022
syms d v
z = acos(0.9);
d = -z+acos(v*cos(z));
p = v/0.06.*sin(d);
dp = diff(p,v);
format long
vmax = double(solve(dp==0,v));
pmax = double(subs(p,v,vmax));
vmax(2)
ans =
0.590098393995658
pmax(2)
ans =
5.223241718943822
V = [ 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1];
D = double(subs(d,v,V));
P = V/0.06.*sin(D);
hold on
plot(V,P)
plot(vmax(2),pmax(2),'o')
hold off
grid on

VBBV on 28 Dec 2022
Edited: VBBV on 28 Dec 2022
k = 1;
for v2=0:0.1:1 ;
sol= solve((v2/.06)*tan(z)*sin(d)==(v2/.06)*cos(d)-((v2*v2)/.06),d);
s=sol;
s2=double(s);
p=(v2/0.06)*sin(s2);
p2{k}=double(p); k = k+1;
end
p2
Walter Roberson on 29 Dec 2022
format long g
syms d
v1=1;
z=acos(0.9);
x12=.06;
v=[ 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 .9 1];
v2vals = linspace(0,1,25);
numv2 = length(v2vals);
for v2idx = 1:numv2
v2 = v2vals(v2idx);
sol = solve((v2/.06)*tan(z)*sin(d)==(v2/.06)*cos(d)-((v2*v2)/.06),d, 'returnconditions', true);
s=sol.d;
if isAlways(s == sol.parameters, 'unknown', 'false')
p2(v2idx,:) = [nan, nan];
fprintf('solve says all values are solutions, iteration #%d\n', v2idx);
else
if ~isempty(sol.parameters)
K = 0;
s = subs(s, sol.parameters, K);
end
s2 = simplify(expand(s)); %double(s);
p = (v2/0.06)*sin(s2);
dp = p; %double(p);
dp(abs(imag(dp))>1e-10) = [];
dp = double(dp);
p2(v2idx, :) = sort(real(dp)); %get rid of negligible imaginary part
end
end
solve says all values are solutions, iteration #1
plot(v2vals, p2)
I added the sort() because the order of the two results was coming out inconsistent.
There are two lines because solve() is finding two solutions each time.