Unable to Write Inline function in Matlab [closed] - windows

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
Unable to Write Inline Aggregate function in Matlab.
X1, X2 are array variables. And mb and nb are size of BUS DATA.
V is the voltage function, delta is the angle.
% objf=inline('sum(V(mb)^2+V(nb)^2-2*V(mb)*V(nb)*cos(delta(mb)-delta(nb)))','mb','nb');
% old code running
objf=inline('4*x1^2-2.1*x1^4+(x1^6)/3+x1*x2-4*x2^2+4*x2^4','x1','x2');**
*Error using inlineeval (line 15)
Error in inline expression ==> sum(V(mb).^2+V(nb).^2-2.*V(mb).*V(nb).cos(delta(mb)-delta(nb)))
Undefined function 'V' for input arguments of type 'double'.
Error in inline/subsref (line 24)
INLINE_OUT_ = inlineeval(INLINE_INPUTS_, INLINE_OBJ_.inputExpr, INLINE_OBJ_.expr);
Error in deeee (line 48)
fx=objf(x(:,1),x(:,2));
where variable aer defined as below..
busdata = bus; % ARRAY OF INPUTs
j=sqrt(-1);
P=[];Q=[];
nb=busdata(:,1);
kb=busdata(:,2);Vm=busdata(:,3);deltad=busdata(:, 4);Pd=0.8*busdata(:,5)/basemva;Qd=.8*busdata(:,6)/basemva;
Pg=busdata(:,7)/basemva;Qg=busdata(:,8)/basemva;Bsh=busdata(:,11);Qmin=busdata(:,9)/basemva;Qmax=busdata(:,10)/basemva;
G=real(Ybus);B=imag(Ybus);slb=find(kb==1);pv=find(kb==2);pq=find(kb==0);pvq=find(kb~=1);npv=length(pv);
npq=length(pq);npvq=length(pvq);nbus=max(nb);
delta(nb) = pi/180*deltad(nb);
V(nb) = Vm(nb).*(cos(delta(nb))+j*sin(delta(nb)))';
P(nb)=(Pg(nb)-Pd(nb));
flag=0;

What you're locking for is anonymous functions
objf = #(mb,nb)sum(V(mb)^2+V(nb)^2-2*V(mb)*V(nb)*cos(delta(mb)-delta(nb)))
objf =
#(mb,nb)sum(V(mb)^2+V(nb)^2-2*V(mb)*V(nb)*cos(delta(mb)-delta(nb)))
objf(1,2)
There you go (as far as all other variables and functions of this anonymous function are defined).

Related

Need help converting a list of CIDR to network ranges. SED/AWK or anything [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 5 years ago.
Improve this question
Ok, so I am trying to convert a list of CIDR formatted ip data into netranges
192.168.1.0/24 I need that, converted to 192.168.1.0-255
In fact, a whole list of addresses. Like this.
101.192.0.0/14
101.202.0.0/16
101.203.128.0/19
101.248.0.0/15
101.252.0.0/15
103.16.76.0/24
103.194.8.0/22
103.197.8.0/22
103.205.84.0/22
103.207.160.0/22
103.210.12.0/22
103.215.80.0/22
103.229.36.0/22
103.229.40.0/22
103.230.144.0/22
103.232.136.0/22
103.232.172.0/22
103.236.32.0/22
Is there any tools readily available that do this? I did some searching before posting this, but nobody else seems to be going for the specific output that I am trying to get here.
Just tried without external commands or libraries.
perl -pe '
m#^(\d+)\.(\d+)\.(\d+)\.(\d+)/(\d+)#;
$_ = "$1.$2.$3.$4-" . join(".", map(hex, sprintf("%X", ($1 << 24) + ($2 << 16) + ($3 << 8) + $4 | (1 << (32 - $5)) - 1) =~ /.{2}/g)) . "\n";
' iplist.txt
I provide the sample script using ipaddress.(Thank you for the instructions, #Jonathon Reinhart )
The prerequisite task is just installing ipaddress module.
# pip install ipaddress
script code: the cidr.list file is including above cidr list.
#!/usr/bin/env python
import ipaddress
file_path='/tmp/cidr.list'
with open(file_path,'r') as cidr_list:
for cidr in cidr_list:
tmp = ipaddress.ip_network(unicode(cidr[:-1]))
print "%s-%s" % (tmp[0],tmp[-1])
output:
101.192.0.0-101.195.255.255
101.202.0.0-101.202.255.255
101.203.128.0-101.203.159.255
101.248.0.0-101.249.255.255
101.252.0.0-101.253.255.255
103.16.76.0-103.16.76.255
103.194.8.0-103.194.11.255
103.197.8.0-103.197.11.255
103.205.84.0-103.205.87.255
103.207.160.0-103.207.163.255
103.210.12.0-103.210.15.255
103.215.80.0-103.215.83.255
103.229.36.0-103.229.39.255
103.229.40.0-103.229.43.255
103.230.144.0-103.230.147.255
103.232.136.0-103.232.139.255
103.232.172.0-103.232.175.255
103.236.32.0-103.236.35.255
I hope this will help you.
Update (thanks #TheAdminsHereAreFags for pointing out sipcalc)
If you have the sipcalc package installed
sipcalc - < iplist.txt | awk '/Network range/{print $4 $5 $6}'
Output
101.192.0.0-101.195.255.255
101.202.0.0-101.202.255.255
101.203.128.0-101.203.159.255
101.248.0.0-101.249.255.255
101.252.0.0-101.253.255.255
103.16.76.0-103.16.76.255
103.194.8.0-103.194.11.255
103.197.8.0-103.197.11.255
103.205.84.0-103.205.87.255
103.207.160.0-103.207.163.255
103.210.12.0-103.210.15.255
103.215.80.0-103.215.83.255
103.229.36.0-103.229.39.255
103.229.40.0-103.229.43.255
103.230.144.0-103.230.147.255
103.232.136.0-103.232.139.255
103.232.172.0-103.232.175.255
103.236.32.0-103.236.35.255

Ruby Yaml - Create instance Variables Directly from a YML file [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
Hi I want to create A YML file and load them as instance variables instead. How can I do that.
yml_File.yml File ::
default:
browserversion: 43
dev:
browser_02: iexplore
qa_01:
browser_default: chrome
qa_02:
browser_default: safari
Check the below Code::
p yml_File = YAML.load_file(File.dirname(__FILE__).gsub('/', '\\') + '\\Profiles.yml')
yml_File.each_key {|key_Value|
va = yml_File[key_Value].to_s
var_name = "##{key_Value}" # the '#' is required
self.instance_variable_set(var_name, va)
p "Name of Instance variable '#{key_Value}' is :: " + var_name.to_s + ' - And Key value is : ' + eval("##{key_Value}")
}
p #dev
p #qa_01
p #qa_02
Note - Ruby 1.9+ atleast

End Function not Recognising - Lua [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 7 years ago.
Improve this question
I have quite the annoying bug right now, whenever I run this code
function player.detect()
for j = #bullet, 1, -1 do
if CheckCollision(bullet[j].x, bullet[j].y, bullet.w, bullet.h, enemy.x, enemy.y, enemy.w, enemy.h) then
table.remove(bullet, j)
end
end
end
for j = #enemy, 1, -1 do
if CheckCollision(bullet.x, bullet.y, bullet.w, bullet.h, enemy[j].x, enemy[j].y, enemy.w, enemy.h) then
table.remove(enemy, j)
end
end
end
end
It says: Error: Syntax error: player.lua:118: '' expected near 'end'
Yes, this is player.lua, and yes the code displayed is line 104-119. Thanks for reading! Anything helps!
You have too many ends!
function player.detect()
for j = #bullet, 1, -1 do
if CheckCollision(bullet[j].x, bullet[j].y, bullet.w, bullet.h, enemy.x, enemy.y, enemy.w, enemy.h) then
table.remove(bullet, j)
end
end
for j = #enemy, 1, -1 do
if CheckCollision(bullet.x, bullet.y, bullet.w, bullet.h, enemy[j].x, enemy[j].y, enemy.w, enemy.h) then
table.remove(enemy, j)
end
end
end

Reformatting a hash with new keys (as symbols) based on date format [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I need to convert this:
[{"day"=>"2014-02-01", "users"=>1234},
{"day"=>"2014-02-02", "users"=>2234},
{"day"=>"2014-02-03", "users"=>3234},
{"day"=>"2014-02-04", "users"=>4234}]
into this:
[{:x=>1, y:=>1234},
{:x=>2, y:=>2234},
{:x=>3, y:=>3234},
{:x=>4, y:=>4234}]
a = [{"day"=>"2014-02-01", "users"=>1234}, {"day"=>"2014-02-02", "users"=>2234}, {"day"=>"2014-02-03", "users"=>3234}, {"day"=>"2014-02-04", "users"=>4234}]
a.map.with_index(1) { |h,i| { :x => i, :y => h['users'] } }
# => [{:x=>1, :y=>1234}, {:x=>2, :y=>2234}, {:x=>3, :y=>3234}, {:x=>4, :y=>4234}]

i need solution for imread [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
i want to load my image call caltrain, there is 30 img.
i used code
for i = 0:30
imgINumber = i;
imgPNumber = i+2;
if imgINumber < 10
imgIFile = sprintf('C:\sequence01_caltrain_gray\caltrain/gray/%s00%d.ras',imageName, imageName, imgINumber);
elseif imgINumber < 100
imgIFile = sprintf('C:\sequence01_caltrain_gray\caltrain/gray/%s0%d.ras',imageName, imageName, imgINumber);
end
if imgPNumber < 10
imgPFile = sprintf('C:\sequence01_caltrain_gray\caltrain\gray/%s00%d.ras',imageName, imageName, imgPNumber);
elseif imgPNumber < 100
imgPFile = sprintf('C:\sequence01_caltrain_gray\caltrain\gray/%s0%d.ras',imageName, imageName, imgPNumber);
end
imgI = double(imread(imgIFile));
imgP = double(imread(imgPFile));
imgI = imgI(:,1:352);
imgP = imgP(:,1:352);
but error:
Error using ==> imread
Can't open file "C:" for reading;
you may not have read permission.
i need solution for this
thanks
Either double your backslashes or replace all the backslashes with slashes in your sprintf calls.

Resources