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)
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

Accepted Answer

Torsten
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 Comments
Mohamed Atef
Mohamed Atef on 29 Dec 2022
Edited: Mohamed Atef on 29 Dec 2022
thank you verymuch . last thing can you tell mehow yo display the point of the peak of the curve at command window @Torsten
Torsten
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

Sign in to comment.

More Answers (1)

VBBV
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
  11 Comments
Walter Roberson
Walter Roberson on 29 Dec 2022
If we postpone the conversion into double precision and we examine the structure of the results, then we can see that even when we use the different multiples of π that the resuls turn out exactly the same. The celldisp() of the diff() shows all zeros (so all results exactly the sqame) except for the one that is intended to represent "all solutions are valid"
And that means that you can pick one of them
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 = 0:0.1:1;
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} = [-inf inf];
fprintf('solve says all values are solutions, iteration #%d\n', v2idx);
else
if ~isempty(sol.parameters)
K = -10:10;
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) = [];
p2{v2idx} = real(dp); %get rid of negligible imaginary part
end
end
solve says all values are solutions, iteration #1
celldisp(p2)
p2{1} = -Inf Inf p2{2} =
p2{3} =
p2{4} =
p2{5} =
p2{6} =
p2{7} =
p2{8} =
p2{9} =
p2{10} =
p2{11} =
celldisp(cellfun(@(C) diff(C,2), p2, 'uniform', 0))
ans{1} = [] ans{2} =
ans{3} =
ans{4} =
ans{5} =
ans{6} =
ans{7} =
ans{8} =
ans{9} =
ans{10} =
ans{11} =
Walter Roberson
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.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!