Python Forum
Problem in creating a vector
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Problem in creating a vector
#11
This is the Matlab cycle that I'm trying to reproduce:

j = 1;
while j < max(length(H_ev_hf_vec),length(H_ev_wf_vec))-1
Q_ev_hf = m_hf*(H_ev_hf_vec(j+1)-H_ev_hf_vec(j));
Q_ev_wf = m_wf*(H_ev_wf_vec(j+1)-H_ev_wf_vec(j));

if Q_ev_hf > Q_ev_wf
H_ev_hf_vec = [H_ev_hf_vec(1:j), H_ev_hf_vec(j)+Q_ev_wf/m_hf, H_ev_hf_vec(j+1:end)];
elseif Q_ev_hf < Q_ev_wf
H_ev_wf_vec = [H_ev_wf_vec(1:j), H_ev_wf_vec(j)+Q_ev_hf/m_wf, H_ev_wf_vec(j+1:end)];
end
j = j+1;
end

But I can't find a way of doing it in Python.
Instead of the command "append", I think it would be more indicated the command "extend", but I'm not able to insert it in the for cycle.
Any solution?
Reply
#12
When translating from one language to another, you have to compare the behavior of each. I'm not sure how MatLab slices sequences (e.g. H_ev_wf_vec(1:j)) but it evidently provides something other than a slice of the sequence; from your statements, it seems like MatLab returns a single value. Is that value a sum of all the values? Is it the highest, lowest, first, or last value?

The presents another problem though. If you begin with a sequence and pull a single value out of it, you won't be able to repeat that operation again because integers are not subscriptable.

So, to replicate the operation MatLab is doing, we need to identify its behavior and build up a solution.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Creating a TG crypto Bot_ problem when trying to with bot.polling p1ner0 1 3,014 Apr-27-2022, 03:43 AM
Last Post: p1ner0
Question How to understand the vector/direction mason321 0 1,999 Dec-14-2021, 10:57 PM
Last Post: mason321
  How to find vector of a 3D plot mason321 0 1,773 Nov-13-2021, 05:05 PM
Last Post: mason321
  How do I make a symmetric matrix from a column vector? leocsmith 3 6,204 Mar-30-2021, 10:17 AM
Last Post: leocsmith
  3D vector class with inheritance from 2D vector class buss0140 4 5,257 Dec-20-2020, 08:44 PM
Last Post: deanhystad
  Problem creating an archive trojantrojan 3 3,570 May-10-2020, 01:32 AM
Last Post: trojantrojan
  Issue with def norm in class Vector DimosG 4 4,209 Mar-26-2020, 05:03 PM
Last Post: DimosG
  Make dual vector dot-product more efficient technossomy 3 4,153 Nov-28-2019, 09:27 PM
Last Post: Gribouillis
  Inaccurate result when a vector is divided by a matrix FromTheColdNorth 3 3,456 Oct-29-2019, 12:06 AM
Last Post: scidam
  Creating Vector from a Program ericvrocha 3 3,368 Oct-08-2019, 07:43 AM
Last Post: newbieAuggie2019

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020