Effacer les filtres
Effacer les filtres

How to perform an operation on a whole column of a matrix?

19 vues (au cours des 30 derniers jours)
Gabriel Venter
Gabriel Venter le 27 Avr 2021
Commenté : Gabriel Venter le 27 Avr 2021
I have the following code, which uses a variable y=1/r for the ODE. I want to convert back to using r, so thought that after solving with ode45 I could just perform the operation on the whole column and be fine, but it isn't working. Clearly I'm doing this wrong, as it runs fine but gives the complete wrong result.
Here is my code:
for i=1:20
G=i/20; %Saving that iterates value of G
[phi,y]=ode45(@(phi,y) odefunction1(phi,y,G), timerange, IC);
y(:,1)=1/(y(:,1)); %this is where I switch back to using r and save it as an element of the cell z. Issue is, its giving me compeltely the wrong result and returning 0 %everywhere for column 1 of y.
z{i}=y;
end
  2 commentaires
Dyuman Joshi
Dyuman Joshi le 27 Avr 2021
Try using this
y(:,1)=1./y(:,1);
Gabriel Venter
Gabriel Venter le 27 Avr 2021
Thanks!

Connectez-vous pour commenter.

Réponses (0)

Catégories

En savoir plus sur Programming dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by