Azzera filtri
Azzera filtri

add givens to formula

9 visualizzazioni (ultimi 30 giorni)
Mohamed EL-Baz
Mohamed EL-Baz il 3 Lug 2021
Commentato: Mohamed EL-Baz il 3 Lug 2021
facing problem on cannot add given numbers to the mention formula so as to appear on a plot.
function velocity = velocity_vector % the flying energy at each frame n to depend only on the velocity vector vc
M = 9.65 ;% in Kg the UAV’s mass, including its payload
sym ('\Delta') = 45 ; % in ms Frame duration
sym('k') = 0.5 .*M \Delta; % Constant for Model 1
sym('\upsilon_{\max}') = 50; % m/s UAV’s maximum speed
sym('P_{n+1}^c') = ('5,0'); % in meters P_F^c Final position of UAV projected onto xy-plane
sym('P_n^c') = ('0,0'); % in meters P_I^c Initial position of UAV projected onto xy-plane
a1 = sym ('\left\|\upsilon_n^c \right\|=\frac{\left\|P_{n+1}^c - P_n^c \right\|}{\Delta}');% UAV’s velocity at the nth frame
if
a1 le ('\upsilon_{\max}');
else
Disp ('velocity vector is bigger than velocity max');
displayformula (a1);
velocity = sym('E_{F,n}^c(\upsilon_n^c)= k{\left\|\upsilon_n^c \right\|}^2');
displayformula(velocity);
plot (velocity);
end
  1 Commento
Mohamed EL-Baz
Mohamed EL-Baz il 3 Lug 2021
M = 9.65 (mass of UAV)
(frame duration)
k= 0.5 * M * \Delta= 0.5 * 9.65 * 45 * 10^(-3) = 0.217125 ,
, (UAV’s maximum speed)
(Final position of UAV projected onto xy-plane)
(Initial position of UAV projected onto xy-plane)

Accedi per commentare.

Risposte (1)

Walter Roberson
Walter Roberson il 3 Lug 2021
sym ('\Delta') = 45 ; % in ms Frame duration
In MATLAB, this creates a double() row vector in which the character vector ['\' 'D' 'e' 'l' 't' 'a'] are converted to their respective character positions 92 68 101 108 116 97 and vector indices at that position are assigned the value 45 and other vector positions 1:67, 69:91 and so on are assigned 0. And afterwards, sym() would not longer be usable as a function.
In MATLAB there is no easy way to create a symbolic variable with a fancy representation such as Δ . It is not entirely impossible
clear sym
delta = sym(evalin(symengine, "`"+char(916)+"`"))
delta = 
Δ
diff(sin(delta)+exp(delta^2),delta)
ans = 
but such names cannot live at the MATLAB level.
If you are using Live Script then Live Script recognizes greek letter names and recognizes single underscore as indicating subscript and recognizes two underscore, __ as indicating superscript
Also, MATLAB has absolutely no implied multiplication -- M Delta would not try to multiply M by Delta
The symbolic toolbox does not recognize comma as decimal separator
You cannot test symbolic expressions that contain unresolved symbolic variables.
You have
a1 = sym ('\left\|\upsilon_n^c \right\|=\frac{\left\|P_{n+1}^c - P_n^c \right\|}{\Delta}');% UAV’s velocity at the nth frame
That is creating an equation relating quantities. It does not define any particular variable. It does not tell you have to calculate velocity; we cannot even tell from there which variable is intended to be holding the velocity.
Later you try to compare the equation to the maximum velocity. You do not solve the equation, and it is meaningless to compare an equation to a value. And since it involves abs() you have to be careful on the comparisons. And you have to be careful because velocity solves to two values but piecewise() cannot handle two values simultaneously
By the time everything is through, your velocity equation can be solved for two specific values. Plotting those values is plotting two constants, which is not interesting.
velocity_vector
velocity = 
solutions = 
ans = 
function velocity = velocity_vector % the flying energy at each frame n to depend only on the velocity vector vc
M = 9.65 ;% in Kg the UAV’s mass, including its payload
Delta = 45 ; % in ms Frame duration
k = 0.5 .* M .* Delta; % Constant for Model 1
upsilon_max = 50; % m/s UAV’s maximum speed
P_np1__c = 5.0; % in meters P_F^c Final position of UAV projected onto xy-plane
P_n__c = 0.0; % in meters P_I^c Initial position of UAV projected onto xy-plane
syms upsilon_n__c
a1 = abs(upsilon_n__c) == abs(P_np1__c - P_n__c) / Delta; % UAV’s velocity at the nth frame
velocity = [-1;1]*solve(a1, upsilon_n__c) %fix because solve only finds positive solution
syms velocity_vector_is_bigger_than_velocity_max velocity_vector_is_in_range
velocity_status = arrayfun(@(V) piecewise(-upsilon_max <= V & V <= upsilon_max, velocity_vector_is_in_range, velocity_vector_is_bigger_than_velocity_max), velocity);
disp(velocity_status)
displayFormula(string(velocity));
syms E_Fn__c
velocity_eqn = E_Fn__c * velocity == k * abs(velocity).^2;
displayFormula(string(velocity_eqn));
solutions = arrayfun(@solve, velocity_eqn)
fplot(solutions)
end

Prodotti


Release

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by