Issues Plotting Equation for a Range of Variable

12 visualizaciones (últimos 30 días)
Daniel Stucki
Daniel Stucki el 3 de Sept. de 2018
Comentada: madhan ravi el 3 de Sept. de 2018
Hello,
I am attempting to plot three equations in MATLAB, over a range of Mach numbers (the primary variable). However, I keep running into either the "Subscript indices must either be real positive integers or logicals" error or the matrix dimensions error. I have tried using ./ over / and .^ over ^ but keep running into the errors.
This is what I have:
% Variables & Given
clear; clc;
ARone = 1; ARtwo = 5; ARthree = 10; k = 1.3;
M = .05:.05:3.4;
E1(M) = ARone - (1 ./ M) .* ((2/k+1)*(1+((k-1)/2) * M.^2)) .^ ((k+1)/(2*(k-1)));
% E2(M) = Atwo - (1/M)*((2/k+1)*(1+((k-1)/2)*M^2))^((k+1)/(2*(k-1)));
% E3(M) = ARthree - (1/M)*((2/k+1)*(1+((k-1)/2)*M^2))^((k+1)/(2*(k-1)));
fplot(E1);
I am just looking to plot E1, E2, and E3 on the same plot. I am just trying to plot each of these equation over the given M interval, from 0.05 to 3.4, using steps of .05.
What am I missing here? Should I remove "
M = .05:.05:3.4;"
and put the range in the fplot command?
Thank you!

Respuesta aceptada

madhan ravi
madhan ravi el 3 de Sept. de 2018
Editada: madhan ravi el 3 de Sept. de 2018
Use plot command because all the variables have values:
% Variables & Given
clear; clc;
ARone = 1;
ARtwo = 5 ;
ARthree = 10;
k = 1.3;
M = .05:.05:3.4;
E1 = ARone - (1 ./ M) .* ((2/k+1)*(1+((k-1)/2) * M.^2)) .^ ((k+1)/(2*(k-1)));
%E2 = Atwo - (1/M)*((2/k+1)*(1+((k-1)/2)*M^2))^((k+1)/(2*(k-1)));
%E3 = ARthree - (1/M)*((2/k+1)*(1+((k-1)/2)*M^2))^((k+1)/(2*(k-1)));
plot(M,E1,'r')
hold on
%plot(M,E2,'g')
%plot(M,E3,'b')
  3 comentarios
Daniel Stucki
Daniel Stucki el 3 de Sept. de 2018
Yes! Thank you so much! Now I have some errors to work out as far as the roots go, but this helped me extremely!
madhan ravi
madhan ravi el 3 de Sept. de 2018
My pleasure @Daniel Stucki

Iniciar sesión para comentar.

Más respuestas (1)

jonas
jonas el 3 de Sept. de 2018
From your code it seems you are trying to utilize function handles, but your syntax is a bit off. Try this instead:
ARone = 1;
ARtwo = 5;
ARthree = 10;
k = 1.3;
E1 = @(M) ARone - (1 ./ M) .* ((2/k+1)*(1+((k-1)/2) * M.^2)) .^ ((k+1)/(2*(k-1)));
E2 = @(M) Atwo - (1/M)*((2/k+1)*(1+((k-1)/2)*M^2))^((k+1)/(2*(k-1)));
E3 = @(M) ARthree - (1/M)*((2/k+1)*(1+((k-1)/2)*M^2))^((k+1)/(2*(k-1)));
fplot(E1,[0.05 3.5]);

Categorías

Más información sobre Mathematics 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!

Translated by